cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
29.89k stars 3.77k forks source link

incorrect usage of require/assert--missing format string results in panic #101028

Open srosenberg opened 1 year ago

srosenberg commented 1 year ago

Functions in github.com/stretchr/testify of the form,

func True(t TestingT, value bool, msgAndArgs ...interface{}) {

expect that when len(msgAndArgs) > 1, the first vararg is a format string [1]. Note the cast in [1] which results in panic unless the first vararg is of type string.

Violations to this contract have been detected in existing tests, e.g., [2]. We should consider adding a linter.

[1] https://github.com/stretchr/testify/blob/c5fc9d6b6b21ea89be8480c0dc35e2977ab988f6/assert/assertions.go#L233 [2] https://github.com/cockroachdb/cockroach/pull/95842

Jira issue: CRDB-26761

blathers-crl[bot] commented 1 year ago

cc @cockroachdb/test-eng

srosenberg commented 1 year ago

A linter using go-ruleguard DSL, which relies on a typed AST finds the following violations in master,