Skip to content
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

Make ErrBadName checkable via errors.Is() #1462

Merged
merged 2 commits into from Oct 14, 2022
Merged

Conversation

cjellick
Copy link
Contributor

@cjellick cjellick commented Oct 13, 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{})

This exact problem was actually discussed when the deprecated warning was introduced: https://github.com/google/go-containerregistry/pull/1164/files#r742970357

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>
@cjellick
Copy link
Contributor Author

The linter didn't like the type assertion I used so I had to change impl to errors.As

Copy link
Collaborator

@imjasonh imjasonh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for this, just one comment.

pkg/name/errors_test.go Outdated Show resolved Hide resolved
Co-authored-by: Jason Hall <jason@chainguard.dev>
@codecov-commenter
Copy link

Codecov Report

Merging #1462 (1f9fb02) into main (7268da0) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           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           
Impacted Files Coverage Δ
pkg/name/errors.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@imjasonh imjasonh merged commit a0f6687 into google:main Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants