Conversation
|
ping @cpuguy83 @vdemeester @wsong @mavenugo PTAL |
api/server/httputils/errors.go
Outdated
There was a problem hiding this comment.
I originally had this at the top to return nil, but not sure what's best. Note that the client actually discards these errors;
Lines 194 to 196 in 3e5b9cb
There was a problem hiding this comment.
Similar implementation 😄 https://github.com/cpuguy83/strongerrors/blob/67f9d3e5dd563226c4b7956e0c1d8f20ffb026d7/status/http.go#L39-L71
Biggest difference (at a glance);
My implementation does not return Unknown for errors if the the status-code is in a known range (i.e. any unknown 4xx error returns an InvalidParameter and any 5xx status return a System error.
Downside is that this may make errors Ambiguous; i.e. a 504 Gateway Timeout (which currently doesn't have a definition / mapping) is transformed into a generic System error. But the original status code is preserved, and can be obtained with err.StatusCode()
This comment has been minimized.
This comment has been minimized.
fc418e6 to
3531246
Compare
|
(reserved for my derek commands) |
3531246 to
a5f0d9e
Compare
Codecov Report
@@ Coverage Diff @@
## master #38467 +/- ##
=========================================
Coverage ? 36.65%
=========================================
Files ? 610
Lines ? 45298
Branches ? 0
=========================================
Hits ? 16606
Misses ? 26409
Partials ? 2283 |
a5f0d9e to
911a6d5
Compare
api/server/httputils/errors.go
Outdated
There was a problem hiding this comment.
NotModified() is in active use (see
Lines 36 to 38 in d4a6e1c
error but not really an error. Maybe just semantics 🤷♂️
This utility allows a client to convert an API response back to a typed error; allowing the client to perform different actions based on the type of error, without having to resort to string-matching the error. Signed-off-by: Sebastiaan van Stijn <[email protected]>
This error-type enables getting the HTTP status code that was returned by the API for further handling. This can be useful for errors that do not have a corresponding error defined in the errdefs package, or errors that are mapped to the same errdef error (alowing the raw status-code to be obtained). Signed-off-by: Sebastiaan van Stijn <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
this patch makes the client return errors matching the errdefs interface. Signed-off-by: Sebastiaan van Stijn <[email protected]>
looks like we don't need this handling
Before this patch:
Error: No such image: nosuchimage
After this patch:
Error response from daemon: No such image: nosuchimage:latest
"
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
911a6d5 to
e7dacbd
Compare
|
Hm... some Windows failure on RS1 |
|
I think maybe instead of creating an interface for this, we should just have a package that you can get the status code from for any error... func HTTPStatusCode(err error) (int, bool)For example |
@cpuguy83 trying to grasp your suggestion; do you mean we'd still add the The point is that if the latter, that there's http statuses that don't map to an errdef, so in that case it would become an |
|
I mean, adding an interface with If there is a status that we can't convert, we should look at adding the right type for it. |
My concern there was a bit that (especially if communication with a registry is involved) we may not know all status-codes upfront, and (I guess) we don't want to be implementing a |
|
We shouldn't need to think about things in terms of http status codes, but rather failure modes and how to communicate that failure mode. In general I did model these interfaces after grpc status codes just because they are pretty well designed and meant exactly for communicating a failure type over the wire. A registry can return whatever it wants, we can only support a subset of that unless the distribution spec defines what a registry should send. |
|
And taking that a step further, it's not even so much failure modes hit recovery modes. |
|
Yeah, perhaps it's sufficient to only handle what we defined; my train of thought was to preserve the information we get, and allow the consumer to still access it through the status code interface. But I'm ok leaving that out, and go for #38689 instead |
The API client currently discards HTTP-status codes that are returned from the daemon. As a result, users of the API client that want to implement logic based on the type of error returned, will have to resort to string-matching (which is brittle).
This PR is a first attempt to make the client return more useful errors;
errdeferrors, so that it's easy to check the type of error (errdef.IsNotFound(err),errdef.IsConflict(err))With this patch, something like the below will be possible;
Feedback needed