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

roachtest: fix parameters passed to require.NoError #95842

Merged
merged 1 commit into from
Jan 25, 2023

Conversation

renatolabs
Copy link
Contributor

When context is passed to an assertion, the parameters must be a string format, followed by arguments (as you would in a call to fmt.Sprintf). The previous code would panic trying to cast int to string.

Informs #95416

Release note: None

When context is passed to an assertion, the parameters *must* be a
string format, followed by arguments (as you would in a call to
`fmt.Sprintf`). The previous code would panic trying to cast int to
string.

Informs cockroachdb#95416

Release note: None
@renatolabs renatolabs requested a review from a team as a code owner January 25, 2023 17:03
@renatolabs renatolabs requested review from herkolategan and srosenberg and removed request for a team January 25, 2023 17:03
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

:lgtm:

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

Copy link
Member

@srosenberg srosenberg left a comment

Choose a reason for hiding this comment

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

:lgtm:

I wonder if this could have been picked up by one of the linters?

Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @herkolategan and @renatolabs)


pkg/cmd/roachtest/tests/multitenant_distsql.go line 142 at r1 (raw file):

					// procede to report error
				}
				require.NoError(t, err, "instance idx = %d, iter = %d", li, iter)

It essentially fails the typecast,

if len(msgAndArgs) > 1 {
	return fmt.Sprintf(msgAndArgs[0].(string), msgAndArgs[1:]...)
}

Copy link
Collaborator

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

@renatolabs
Copy link
Contributor Author

I wonder if this could have been picked up by one of the linters?

We don't have any linters checking for that (not sure if there's something out there that we could use, a quick Google search didn't reveal anything).

bors r=yuzefovich,srosenberg,herkolategan

@srosenberg
Copy link
Member

We don't have any linters checking for that (not sure if there's something out there that we could use, a quick Google search didn't reveal anything).

fmtsafe.Analyzer [1] does essentially what we want in this case, no?

[1]

- that the format string in Infof(), Errorf() and similar calls is a

@renatolabs
Copy link
Contributor Author

fmtsafe.Analyzer [1] does essentially what we want in this case, no?

Not quite? It is similar, but it makes two assumptions that wouldn't work well for this purpose:

  • it ensures the format argument passed to the fmt-like fuctions is a constant string. This seems overly restrictive for this use case.
  • It's equipped to verify functions with the following signature f(format string, args ...interface{}). The require-style calls here have the format f(msgAndArgs ...interface{}), where the "format" is part of the variadic args.

In other words, we'd have to teach the semantics of require to the linter, which is not ideal: we'd have to change the description of the linter to:

checks that log and error functions don't leak PII -- and also checks `require` calls while at it

That said, this is a good experiment for the tools you mentioned recently (revive / ruleguard); I'll play with this later.

@craig
Copy link
Contributor

craig bot commented Jan 25, 2023

Build succeeded:

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