-
Notifications
You must be signed in to change notification settings - Fork 279
sync: coreth PR #1303 style: Use require.ErrorIs whenever possible #1875
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
base: master
Are you sure you want to change the base?
sync: coreth PR #1303 style: Use require.ErrorIs whenever possible #1875
Conversation
| // "your custom test name": { | ||
| // Config: NewConfig(utils.NewUint64(3), {{- if .Contract.AllowList}} admins, enableds, managers{{- end}}), | ||
| // ExpectedError: ErrYourCustomError.Error(), | ||
| // WantError: ErrYourCustomError, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this break dependent users?
|
|
||
| var ErrCannotAddManagersBeforeDurango = errors.New("cannot add managers before Durango") | ||
| var ( | ||
| ErrAdminAndEnabledAddress = errors.New("cannot set address as both admin and enabled") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these all need exported?
| if oldErr != nil { | ||
| require.ErrorContains(err, oldErr.Error()) | ||
| require.ErrorIs(err, oldErr) | ||
| } else { | ||
| require.NoError(err) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if oldErr != nil { | |
| require.ErrorContains(err, oldErr.Error()) | |
| require.ErrorIs(err, oldErr) | |
| } else { | |
| require.NoError(err) | |
| } | |
| require.ErrorIs(err, oldErr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the same below
| _, err := allowListTest.DeployContract(unprivileged) | ||
| // The error returned is a JSON Error rather than the vm.ErrExecutionReverted error | ||
| require.ErrorContains(t, err, vm.ErrExecutionReverted.Error()) | ||
| // The error returned is actually a JSON Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other comment was more informative, and more accurately describes why we need the nolint clause than "uses upstream code"
| unpacked, err := UnpackGetFeeConfigOutput(test.input, test.skipLenCheck) | ||
| if test.expectedErr != "" { | ||
| require.ErrorContains(t, err, test.expectedErr) | ||
| require.ErrorContains(t, err, test.expectedErr) //nolint:forbidigo // uses upstream code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, you should wrap the error returned by UnpackGetFeeConfigOutput and check for that error
| unpacked, err2 := UnpackSetFeeConfigInput(input, true) | ||
| if err != nil { | ||
| require.ErrorContains(t, err2, err.Error()) | ||
| require.Equal(t, err.Error(), err2.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use ErrorIs?
| if err != nil { | ||
| require.ErrorContains(t, err2, err.Error()) | ||
| require.ErrorIs(t, err2, err) | ||
| return | ||
| } | ||
| require.NoError(t, err2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if err != nil { | |
| require.ErrorContains(t, err2, err.Error()) | |
| require.ErrorIs(t, err2, err) | |
| return | |
| } | |
| require.NoError(t, err2) | |
| require.ErrorIs(t, err2, err) | |
| if err != nil { | |
| return | |
| } |
this applies to to whole file
| unpackedAddress, unpackedAmount, err := UnpackMintNativeCoinInput(test.input, test.strictMode) | ||
| if test.expectedErr != "" { | ||
| require.ErrorContains(t, err, test.expectedErr) | ||
| require.ErrorContains(t, err, test.expectedErr) //nolint:forbidigo // uses upstream code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, you should be able to fix this
| if err != nil { | ||
| require.ErrorContains(t, err2, err.Error()) | ||
| require.ErrorIs(t, err2, err) | ||
| return | ||
| } | ||
| require.NoError(t, err2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the NoError by moving the ErrorIs outside of the if statement
|
|
||
| var ( | ||
| _ Backend = (*backend)(nil) | ||
| ErrValidateBlock = errors.New("failed to validate block message") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do these have to be exported?
Syncs ava-labs/coreth#1303