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

server,cli: fix improperly wrapped errors #72352

Merged
merged 1 commit into from
Nov 3, 2021

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 review from knz and a team November 2, 2021 20:54
@rafiss rafiss requested a review from a team as a code owner November 2, 2021 20:54
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

very nice. I already love your linter.

Reviewed 5 of 5 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)


pkg/cli/clisqlclient/conn_test.go, line 68 at r1 (raw file):

	testutils.SucceedsSoon(t, func() error {
		if sqlRows, err := conn.Query(`SELECT 1`, nil); !errors.Is(err, driver.ErrBadConn) {
			return errors.AssertionFailedf("expected ErrBadConn, got %v", err)

NewAssertionErrorWithWrappedErrf? same below


pkg/server/drain_test.go, line 90 at r1 (raw file):

			return nil
		}
		return errors.AssertionFailedf("server not yet refusing RPC, got %v", err)

assertion with wrap

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! 0 of 0 LGTMs obtained (waiting on @knz)


pkg/cli/clisqlclient/conn_test.go, line 68 at r1 (raw file):

Previously, knz (kena) wrote…

NewAssertionErrorWithWrappedErrf? same below

Done.


pkg/server/drain_test.go, line 90 at r1 (raw file):

Previously, knz (kena) wrote…

assertion with wrap

Done.

@rafiss rafiss force-pushed the fix-server-cli-errwrap branch 2 times, most recently from 330685b to b12219b Compare November 3, 2021 02:07
@rafiss
Copy link
Collaborator Author

rafiss commented Nov 3, 2021

tftr!

bors r=knz

@craig
Copy link
Contributor

craig bot commented Nov 3, 2021

Build failed:

@rafiss
Copy link
Collaborator Author

rafiss commented Nov 3, 2021

bors r=knz

craig bot pushed a commit that referenced this pull request Nov 3, 2021
72352: server,cli: fix improperly wrapped errors r=knz 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

Co-authored-by: Rafi Shamim <[email protected]>
@craig
Copy link
Contributor

craig bot commented Nov 3, 2021

Build failed:

@rafiss
Copy link
Collaborator Author

rafiss commented Nov 3, 2021

bors r=knz

@craig
Copy link
Contributor

craig bot commented Nov 3, 2021

Build failed (retrying...):

@knz
Copy link
Contributor

knz commented Nov 3, 2021

bors r-

@craig
Copy link
Contributor

craig bot commented Nov 3, 2021

Canceled.

@knz
Copy link
Contributor

knz commented Nov 3, 2021

made a mistake in review

Copy link
Contributor

@knz knz 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! 0 of 0 LGTMs obtained (waiting on @knz and @rafiss)


pkg/server/drain_test.go, line 90 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

Done.

please revert this one. we want an error to be returned by this function when Dial returns a nil error.

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! 0 of 0 LGTMs obtained (waiting on @knz)


pkg/server/drain_test.go, line 90 at r1 (raw file):

Previously, knz (kena) wrote…

please revert this one. we want an error to be returned by this function when Dial returns a nil error.

not sure what the best way to do this is while still keeping the forthcoming linter happy. i could do

		errS := "<nil>"
		if err != nil {
			errS = err.Error()
		}
		return errors.Newf("server not yet refusing RPC, got %s", errS)

which seems gross.

should i keep it as is and instead allow a //nolint directive similar to

if strings.Contains(c.Text, "nolint:fmtsafe") {

@knz
Copy link
Contributor

knz commented Nov 3, 2021

yes a nolint comment in this case seems appropriate.
you can also do:

if err != nil {
   if grpc.XXX(err) {
     return nil
   }
   return errors.NewAssertion...(err, "...")
}
// nil err
return errors.AssertionFailed("dial did not fail")

@rafiss
Copy link
Collaborator Author

rafiss commented Nov 3, 2021

thanks, i'll add nolint support when i introduce the linter

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-server-cli-errwrap branch from b12219b to 2407d3f Compare November 3, 2021 18:50
@rafiss
Copy link
Collaborator Author

rafiss commented Nov 3, 2021

tftr!

bors r=knz

@craig
Copy link
Contributor

craig bot commented Nov 3, 2021

Build succeeded:

@craig craig bot merged commit 3bc13c2 into cockroachdb:master Nov 3, 2021
@rafiss rafiss deleted the fix-server-cli-errwrap branch November 3, 2021 21:08
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.

3 participants