-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve error message for prepare step #375
Conversation
it("wraps unhandled server errors with a reasonable error message", func() { | ||
handler.HandleFunc("/v2/", func(writer http.ResponseWriter, request *http.Request) { | ||
writer.WriteHeader(500) | ||
}) | ||
|
||
hasAccess, err := HasWriteAccess(testKeychain{}, tagName) | ||
require.Error(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a matcher called EqualError
that allows one to also assert on the error message in the same require, but that is a minor nit.
Codecov Report
@@ Coverage Diff @@
## master #375 +/- ##
=======================================
Coverage 67.52% 67.53%
=======================================
Files 81 81
Lines 3307 3308 +1
=======================================
+ Hits 2233 2234 +1
Misses 800 800
Partials 274 274
Continue to review full report at Codecov.
|
pkg/dockercreds/access_checker.go
Outdated
@@ -39,6 +39,7 @@ func HasWriteAccess(keychain authn.Keychain, tag string) (bool, error) { | |||
} | |||
} | |||
|
|||
err = errors.Errorf("Error validating write permission to %s. %s", tag, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errors are always confusing in go but, this should be an error wrap.
errors.Wrapf(err, "message %s", thing)
Right now we have two mechanisms to print errors to the user. Either the I wonder if |
im into this!! |
Aye. that makes sense. Apply the same approach to |
|
Awesome! What does the updated output look like for 401 and 500 cases? |
I captured the output for 500 in the commit message. Also below:
Did not keep a copy of the output for a 401.. But, the message should be prefixed identically Let me grab the output from an actual run and will update soon. |
Checked against dockerhub with invalid creds for the 401 case:
|
(Harbor specific weird case) also the now fails with the consistent prefix and a lot more verbose error message. The additional error message was previously lost behind the
|
I think we can merge. I know in the past we explicitly made the decision to not show the entire verbose error message on common 401s because it is a bit confusing message with information they don't need to understand. Do you think that extra information is valuable in the 401 case? |
Sorry, was not aware of the preference to limit the verbose error message! From what, I understand it's a case of seeing
vs
To be honest, I like seeing as much detail as possible :) |
Made error messages less verbose for known errors How errors look now:
|
- wrap unhandled server errors returnd by container registry with a more reasonable error message - removed redundant code from test file Before: ``` [prepare] GET https://dev.registry.pivotal.io/service/token?scope=repository%3Agarbage%3Apush%2Cpull&service=harbor-registry: unsupported status code 500 ``` After: ``` [prepare] Error validating write permission to dev.registry.pivotal.io/garbage. GET https://dev.registry.pivotal.io/service/token?scope=repository%3Agarbage%3Apush%2Cpull&service=harbor-registry: unsupported status code 500 ``` Signed-off-by: Sukhil Suresh <ssuresh@pivotal.io>
- Refactor `HasWriteAccess` and `HasReadAccess` to `VerfiyWriteAccess` and `VerifyReadAccess`. Both methods now only return an error instead of an error and bool. - make use of `errors.Wrapf(..)` - make use of `assert.EqualError(..)` Updated error message format: ``` [prepare] Error verifying write access to "dev.registry.pivotal.io/garbage": GET https://dev.registry.pivotal.io/service/token?scope=repository%3Agarbage%3Apush%2Cpull&service=harbor-registry: unsupported status code 500 ``` Signed-off-by: Sukhil Suresh <ssuresh@pivotal.io>
How errors look now: 500 ``` [prepare] Error verifying write access to "dev.registry.pivotal.io/garbage": GET https://dev.registry.pivotal.io/service/token?scope=repository%3Agarbage%3Apush%2Cpull&service=harbor-registry: unsupported status code 500 ``` 401 ``` [prepare] Error verifying write access to "index.docker.io/sukhilsuresh/spring-petclinic": UNAUTHORIZED ``` harbor special case (diagnosed as unauthorized) ``` [prepare] Error verifying write access to "dev.registry.pivotal.io/garbage/garbage": UNAUTHORIZED ``` Signed-off-by: Sukhil Suresh <ssuresh@pivotal.io>
I know it's merged, but noticed when testing (again) that the above statement is inaccurate. The harbor special case
To be fair, this is bit of an outlier case/error, but still... :( The 401s and 500 work as expected. |
Before:
After:
Signed-off-by: Sukhil Suresh ssuresh@pivotal.io