Skip to content

Make ErrBadName checkable via errors.Is()#1462

Merged
imjasonh merged 2 commits intogoogle:mainfrom
cjellick:is-error-fix
Oct 14, 2022
Merged

Make ErrBadName checkable via errors.Is()#1462
imjasonh merged 2 commits intogoogle:mainfrom
cjellick:is-error-fix

Conversation

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

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

Copy link
Copy Markdown
Contributor

@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.

Co-authored-by: Jason Hall <jason@chainguard.dev>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Oct 14, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.32%. Comparing base (7268da0) to head (1f9fb02).
Report is 172 commits behind head on main.

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.
📢 Have feedback on the report? 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.

4 participants