Skip to content

Replace deprecated usages of assert.ErrorType#5312

Closed
laurazard wants to merge 1 commit intodocker:masterfrom
laurazard:fix-deprecated-warnings
Closed

Replace deprecated usages of assert.ErrorType#5312
laurazard wants to merge 1 commit intodocker:masterfrom
laurazard:fix-deprecated-warnings

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)

@laurazard laurazard self-assigned this Aug 1, 2024
@laurazard laurazard requested review from thaJeztah and vvoland August 1, 2024 11:00
@codecov-commenter
Copy link

codecov-commenter commented Aug 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.01%. Comparing base (ddd4c39) to head (508337b).
Report is 632 commits behind head on master.

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.

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;

@thaJeztah
Copy link
Member

New version of gotest.tools was released that un-deprecates this; I opened a PR to update to that version;

@laurazard
Copy link
Member Author

Yayyy 🥳 Will close this.

@laurazard laurazard closed this Feb 9, 2025
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