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

Replace deprecated usages of assert.ErrorType #5312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

laurazard
Copy link
Member

@laurazard laurazard commented Aug 1, 2024

- What I did

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
@laurazard laurazard self-assigned this Aug 1, 2024
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.01%. Comparing base (ddd4c39) to head (508337b).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5312      +/-   ##
==========================================
- Coverage   61.45%   61.01%   -0.45%     
==========================================
  Files         299      296       -3     
  Lines       20855    20847       -8     
==========================================
- Hits        12816    12719      -97     
- Misses       7124     7211      +87     
- Partials      915      917       +2     

Comment on lines +82 to +83
var expectedError *pluginError
assert.Check(t, errors.As(p.Err, &expectedError))
Copy link
Member

Choose a reason for hiding this comment

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

Oh! I recall some fun cases where there's no good replacement, or at least errors.As / errors.Is for sure has a bunch of pitfalls; see the discussion I had with the gotest.tools authors on gotestyourself/gotest.tools#272

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed. This works, but the errors.As "pointer-to-pointer" stuff is.. not nice to use.

Copy link
Member

Choose a reason for hiding this comment

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

It's really horrible, and very easy to get wrong (in which case, it's even possible to get the unexpected result). I honestly really hate the errors.As / errors.Is handling for that reason.

@@ -18,7 +17,7 @@ func TestRemove(t *testing.T) {
_, err := cli.ContextStore().GetMetadata("current")
assert.NilError(t, err)
_, err = cli.ContextStore().GetMetadata("other")
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
assert.Check(t, errdefs.IsNotFound(err))
Copy link
Member

Choose a reason for hiding this comment

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

To keep the current (more informative) output of is.ErrorType, we should probably use the 3rd argument of assert.Check to write a custom error message (wanted %T, actual %T or something along those lines), but it will definitely make the code a lot more lengthy/verbose 😞

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh, yeah I just saw you mention the nicer output (I definitely wondered why we were using Errortype(err, errdefs.IsXxx)) in the thread with the gotest.tools folks.

Copy link
Member

Choose a reason for hiding this comment

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

If we want to continue using the is.ErrorType, I think Daniel was open to un-deprecating it (IIUC, reason for deprecating was mostly cleaning up ("stdlib now has utilities for it, and the alternative can work, so let's deprecate"). We can open a PR to do so, and see if they're ok with it.

@thaJeztah
Copy link
Member

FWIW, I opened a PR to see if un-deprecating is acceptable;

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.

3 participants