Commit Graph

15 Commits

Author SHA1 Message Date
Paul Holzinger 888702d1fb
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č 4236939b6c 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č 23d7e70104 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č d55a5eb6a3 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č 25f9cea5c8 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č 24359e09d1 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č 524ce57987 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č 6fa5cda402 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č f7ab2cc9f0 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č 5fdfa20df7 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č c75a4e96b5 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č 5283de11ce 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č 8edcf5a7ca 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 49113724f1
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č cf6dd8eb46 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