Commit Graph

15 Commits

Author SHA1 Message Date
Paul Holzinger ca2aae323c docker: export UnexpectedHTTPStatusError
Some callers might like to make decisions based on the http server error
that was returned.

In particular we would like c/common/pkg/retry to match this error so it
can retry image pulls/pushes on 5XX errors as they seems to be a quite
common problem[1].

[1] https://github.com/containers/common/issues/2299

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-03-21 17:36:18 +01:00
Miloslav Trmač 694696501f Use testify's ErrorAs to simplify tests a bit
Should not change (test) behavior, other than perhaps
better test failure output.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-11-25 20:41:50 +01:00
Miloslav Trmač 5e98ea38e7 Recognize "manifest unknown" errors reported by Harbor
... per data in https://github.com/containers/image/issues/2203 .

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-05-16 18:19:56 +02:00
Miloslav Trmač 55552fac88 Quote the response body in an error message
... to make sure we don't output raw control characters, for example.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-11-14 00:05:53 +01:00
Miloslav Trmač 786e2397a9 Close http.Response.Body
golangci-lint linter: bodyclose

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-06 21:15:45 +01:00
Miloslav Trmač 60f45a859b s/interface{}/any/g
... in almost all cases.

Also rename mSI (map[string]interface{}) to mSA (map[string]any).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-03 18:34:11 +01:00
Miloslav Trmač e3ebf5ca77 Recognize invalid error responses of registry.redhat.io
... when checking for missing images.

In particular, this is necessary for use-sigstore-attachments not to
cause failures when pulling from registry.redhat.io.

Red Hat internal reference: RITM1310318

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-13 22:21:34 +02:00
Miloslav Trmač 100c425100 Simplify error messages using the default error text
E.g. use "authentication required" instead of "unauthorized: authentication required".

See the tests for more examples.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-12 21:48:04 +02:00
Miloslav Trmač 9f568d97b3 Use registryHTTPResponseToError on /tags/list failure
We should have been doing that from the start, in order to
get server-reported errors correctly.

NOTE: This can break existing clients, notably (skopeo inspect)
which greps the error string for 401 and 403.  See the corresponding
skopeo PR for documentation of what we do about that.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-12 21:48:04 +02:00
Miloslav Trmač 982f5f708b Make invalid HTTP bodies unwrappable as unexpectedHTTPResponseError
... through errors.Unwrap().  Should not change the user-visible
text of the error; this is only to make the internal error type
usable through registryHTTPResponseToError, as a matter of general
cleanliness.

The unexpectedHTTPResponseError type is private anyway, so this
is not externally-observable.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-12 21:48:04 +02:00
Miloslav Trmač 6c25725bcc Add more detailed error tests
In particular, add specific errcode.ErrorCoder values, which is
what callers are actually looking for.

Also allow for special cases.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-12 21:48:04 +02:00
Miloslav Trmač 72fe6c6019 Discard any but the first element of errcode.Errors
... to simplify user-visible error messages, and to make the
errors less ambiguous for errcode.ErrorCoder testing.

NOTE: This may break callers that expect the full errcode.Errors.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-12 21:48:04 +02:00
Miloslav Trmač 20649ac48d Update the public.ecr.aws error with current data
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-12 21:48:04 +02:00
Paul Holzinger 5ace7abca5 Remove github.com/docker/distribution/registry/client package
Using the github.com/docker/distribution/registry/client package will
import many huge prometheus dependencies, e.g.
 * github.com/prometheus/client_golang/prometheus/promhttp
 * github.com/prometheus/client_golang/prometheus
 * github.com/prometheus/procfs
and even more...

All of these dependencies are completely unused AFAICT but will still end
up in a binary because they are imported transitive.

github.com/docker/distribution/registry/client is only used to check
http errors so I think it makes sense to copy only the required code
into the docker package.

I vendored this commit into podman and it saves over 700KB in binary
size.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-09-06 18:40:49 +02:00
Miloslav Trmač dc76913200 Add tests for httpResponseToError
It's high time we started collecting error samples and
documenting what happens.

NOTE: This is NOT an API commitment, we can change the error
types and messages any time.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-08-26 02:49:30 +02:00