Make ErrBadName checkable via errors.Is()#1462
Merged
imjasonh merged 2 commits intogoogle:mainfrom Oct 14, 2022
Merged
Conversation
jonjohnsonjr
approved these changes
Oct 14, 2022
The function IsErrBadName says it is deprecated and directs the user to
use errors.Is(), but that will never return true because this error is
custom based on the tag value.
This fixes that problem by implementing an Is() function on ErrBadName
so that errors.Is() can properly identify the error as an ErrBadName.
Usage can now be: errors.Is(err, &ErrBadName{})
Signed-off-by: Craig Jellick <craig@acorn.io>
54d0b4a to
1af0b88
Compare
Contributor
Author
|
The linter didn't like the type assertion I used so I had to change impl to errors.As |
imjasonh
reviewed
Oct 14, 2022
Contributor
imjasonh
left a comment
There was a problem hiding this comment.
Nice! Thanks for this, just one comment.
Co-authored-by: Jason Hall <jason@chainguard.dev>
imjasonh
approved these changes
Oct 14, 2022
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1462 +/- ##
=======================================
Coverage 73.31% 73.32%
=======================================
Files 115 115
Lines 8772 8775 +3
=======================================
+ Hits 6431 6434 +3
Misses 1696 1696
Partials 645 645 ☔ View full report in Codecov by Sentry. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The function IsErrBadName says it is deprecated and directs the user to
use errors.Is(), but that will never return true because this error is
custom based on the tag value.
This fixes that problem by implementing an Is() function on ErrBadName
so that errors.Is() can properly identify the error as an ErrBadName.
Usage can now be: errors.Is(err, &ErrBadName{})
This exact problem was actually discussed when the deprecated warning was introduced: https://github.com/google/go-containerregistry/pull/1164/files#r742970357