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

*: fix improperly wrapped errors #72353

Merged
merged 1 commit into from
Nov 4, 2021
Merged

Conversation

rafiss
Copy link
Collaborator

@rafiss rafiss commented Nov 2, 2021

refs #42510

I'm working on a linter that detects errors that are not wrapped
correctly, and it discovered these.

Release note: None

@rafiss rafiss requested a review from a team as a code owner November 2, 2021 20:55
@rafiss rafiss requested a review from a team November 2, 2021 20:55
@rafiss rafiss requested review from a team as code owners November 2, 2021 20:55
@rafiss rafiss requested review from otan and removed request for a team November 2, 2021 20:55
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@rafiss rafiss force-pushed the fix-extra-errwrap branch from cd547cd to 664f622 Compare November 2, 2021 23:15
@rafiss rafiss force-pushed the fix-extra-errwrap branch 2 times, most recently from dcb0ad6 to 634fd19 Compare November 3, 2021 01:56
Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @RaduBerinde and @rafiss)


pkg/testutils/sqlutils/sql_runner.go, line 120 at r1 (raw file):

		_, err := sr.DB.ExecContext(context.Background(), query, args...)
		if !testutils.IsError(err, errRE) {
			return errors.AssertionFailedf("expected error '%s', got: %v", errRE, err)

[nit] I don't think this should be an AssertionFailed (we don't really care to see this stack). I would just extract errStr := err.Error() and use that with Newf().

Copy link
Collaborator

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

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

Left two questions, but overall it looks good.

The fmt.Errorf -> errors.Wrap transformation isn't necessarily equivalent, but I checked all the ones here and they seem OK. I flagged one we might want to double-check.

@@ -310,7 +310,7 @@ func run() error {
}
return err
default:
return fmt.Errorf("unexpected context error: %v", err)
return errors.Wrap(err, "unexpected context error")
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like before this would always return an error whereas this might now return nil. However, I'm not sure it matters because I believe Err() only ever returns the two errors already caught in the switch above.

@@ -117,7 +117,7 @@ func (sr *SQLRunner) ExpectErrSucceedsSoon(
sr.succeedsWithin(t, func() error {
_, err := sr.DB.ExecContext(context.Background(), query, args...)
if !testutils.IsError(err, errRE) {
return errors.Newf("expected error '%s', got: %v", errRE, err)
return errors.AssertionFailedf("expected error '%s', got: %v", errRE, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For my own understanding, why are we preferring AssertionFailedf in these cases?

Copy link
Collaborator Author

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @RaduBerinde, @rafiss, and @stevendanna)


pkg/cmd/roachprod-stress/main.go, line 313 at r1 (raw file):

Previously, stevendanna (Steven Danna) wrote…

It looks like before this would always return an error whereas this might now return nil. However, I'm not sure it matters because I believe Err() only ever returns the two errors already caught in the switch above.

more importantly:

	// If Done is closed, Err returns a non-nil error explaining why:

pkg/testutils/sqlutils/sql_runner.go, line 120 at r1 (raw file):

Previously, stevendanna (Steven Danna) wrote…

For my own understanding, why are we preferring AssertionFailedf in these cases?

my thinking was that it made sense since the test is asserting that the error is the expected type. but i agree with the point that the stack in this case is useless, so i'll change it back

actually, it's worth doing it explicitly anyway since err.Error() or %v doesn't show things like error details/hints, which might be useful to show here too.

@rafiss rafiss force-pushed the fix-extra-errwrap branch from 634fd19 to b42548c Compare November 3, 2021 19:38
@rafiss
Copy link
Collaborator Author

rafiss commented Nov 3, 2021

merging since failure is from a flaky test

bors r=otan,RaduBerinde,stevendanna

@craig
Copy link
Contributor

craig bot commented Nov 3, 2021

Build failed:

I'm working on a linter that detects errors that are not wrapped
correctly, and it discovered these.

Release note: None
@rafiss rafiss force-pushed the fix-extra-errwrap branch from b42548c to b1eba61 Compare November 4, 2021 15:47
@rafiss
Copy link
Collaborator Author

rafiss commented Nov 4, 2021

bors r=otan,RaduBerinde,stevendanna

craig bot pushed a commit that referenced this pull request Nov 4, 2021
72304: bazel: add `pkg/cmd/mirror` r=rail a=rickystewart

This tool will be extended with functionality to mirror Go module ZIP's
to cloud storage. For now, the mirroring functionality is missing, so
we just generate the `DEPS.bzl` content in much the same way as
`gazelle update-repos` does. (This doesn't change the content of
`DEPS.bzl` in any way besides alphabetizing the contents.)

Release note: None

72353: *: fix improperly wrapped errors r=otan,RaduBerinde,stevendanna a=rafiss

refs #42510

I'm working on a linter that detects errors that are not wrapped
correctly, and it discovered these.

Release note: None

72417: sql: add unit tests for creating default privileges r=ajwerner a=RichardJCai

Adding some unit test coverage so we don't hit bugs like this again.
#72322

Release note: None

Co-authored-by: Ricky Stewart <[email protected]>
Co-authored-by: Rafi Shamim <[email protected]>
Co-authored-by: richardjcai <[email protected]>
Co-authored-by: Richard Cai <[email protected]>
@craig
Copy link
Contributor

craig bot commented Nov 4, 2021

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Nov 4, 2021

Build succeeded:

@craig craig bot merged commit ed35bbe into cockroachdb:master Nov 4, 2021
@rafiss rafiss deleted the fix-extra-errwrap branch November 22, 2021 05:32
craig bot pushed a commit that referenced this pull request Dec 15, 2021
71877: lint: add new errwrap linter r=ajwerner,knz a=rafiss

fixes #42510

This linter checks if we don't correctly wrap errors.

The `/* nolint:errwrap */` comment can be used to disable the linter inline.

See individual commits for mistakes this linter caught.
It had already caught a few in #72353, #72352, #72351, #72350, and #72349.

Release note: None

Co-authored-by: Rafi Shamim <[email protected]>
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.

5 participants