Commit Graph

22 Commits

Author SHA1 Message Date
Paul Holzinger 3948fe04a0 docker: expand use of UnexpectedHTTPStatusError
So that callers can actually check the status code of all requests if
needed. This changes error text slightly but I think it still carries
the same meaning.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-03-24 11:47:48 +01:00
Carlos Rodriguez-Fernandez fb5b9ce20e registry: remove ping v1
The ping v1 happens when the ping v2 fails, however, it causes the ping
v2 error to be skipped and not output to the user. As result, when a
registry has v1 and v2 enabled, and there are, for example, intermittent
connectivity issues making the ping v2 fail, the user is presented with
a misleading error saying "can't talk to V1 registry."

Since the only use of v1 is for the search API as a workaround for
docker.io, and new container registries setups are very unlikely to be
v1-only, there is little utility in keeping this v1 detection in the
attempt to help the user realize their setup is v1-only, hence not
compatible. On the contratry, it just presents the user with a
misleading error in certain circumstances.

Signed-off-by: Carlos Rodriguez-Fernandez <carlosrodrifernandez@gmail.com>
2024-10-02 15:13:10 +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č 044c5be3c3 opencontainers/distribution-spec does not require errors to carry JSON
... so update one of our checks to rely on the specified status (only).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-08-10 19:49:32 +02:00
Miloslav Trmač a992dc7a93 Use short-form assignments in various places
golangci-lint linter: gocritic

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-06 21:23:14 +01: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č 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č 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č fa5f65b0de Consolidate handleErrorResponse calls to registryHTTPResponseToError
... so that we can modify the handleErrorResponse consumption
logic in one place.

Note that this may change the user-visible error message.

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č 564fc01baf Remove uses of errors.Errorf
This means we won't save the stack, which is cheaper
(and possibly might break callers' format strings that
want to print the stack, but we never promised the stack
to be available).

Use either fmt.Errorf, or errors.New (usually as a local
edit, not carring about errors.new vs. pkg/errors.New;
that's going to be cleaned up later).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-30 21:45:07 +02:00
Miloslav Trmač 47d4730c05 Add a comment to httpResponseToError
Make it harder to not use the right function.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-08-26 03:33:10 +02:00
Miloslav Trmač b9021c96eb Handle the GetBlobAt special cases of HTTP status code in there
No point in handling them in generic code, and callers that
aren't expecting StatusPartialContent could be confused.

Should not change behavior of GetBlobAt; might in change behavior of
other callers if they unexpectedly received the relevant HTTP status
codes.

This ~mechanically moves the code without much restructuring.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-08-26 03:33:10 +02:00
Miloslav Trmač 711c3bae40 Simplify a check for client.UnexpectedHTTPResponseError
github.com/docker/distribution is not using the github.com/pkg/errors
wrapping mechanism, and we don't expect them to start.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-08-26 03:33:10 +02:00
Miloslav Trmač 04085703a2 Rename errResponse to err
just to minimize repetition; the Reponse qualifier applies to
everything in that function, so it doesn't help.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-08-26 03:33:10 +02:00
Giuseppe Scrivano 29ab1715da docker: support partial blob retrieval
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-07-02 14:36:51 +02:00
Daniel J Walsh 113947dfda Change all references to docker registry to container registry
Will leave references to distribution spec until there is an OCI Spec we
can point at.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-06-30 15:34:06 -04:00
Qi Wang 468703c8a5 Return error body if UnexpectedHTTPResponseError
Format the error message use the response body if the original error is returned as client.UnexpectedHTTPResponseError type

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-08-31 20:31:10 -04:00
Miloslav Trmač 272fed3bb4 Fix up the wording a bit in various places
E.g.
- Capitalize log messages
- Add a bit more context to the log messages
- Don't commit to specific fallback behavior in the API, only say that it may automatically retry.
- Fix some typos

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Miloslav Trmač 59d8fb9554 Re-add some context to unexpected HTTP status errors
... to indicate the operation that failed

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Qi Wang 837b46dbdb return resp error message
follow https://github.com/containers/image/pull/709
return and wrap http response message to show server-side error message.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2019-10-24 14:20:06 -04:00
Valentin Rothberg 2587a9b3a9 docker: handle http 429 status codes
Consolidate checking the http-status codes to allow for a more uniform
error handling.  Also treat code 429 (too many requests) as a known
error instead of an invalid status code.

When hitting 429, perform an exponential back off starting a 2 seconds
for at most 5 iterations.  If the http.Response set the `Retry-Header`
then use the provided value or date to compute the delay until the
next attempt.  Note that the maximum delay is 60 seconds.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-10-18 11:47:57 +02:00