Skip to content

*: add linter rule to disallow panic(fmt.Sprintf())#5834

Merged
annrpom merged 3 commits intocockroachdb:masterfrom
annrpom:panic-lint-rule
Mar 12, 2026
Merged

*: add linter rule to disallow panic(fmt.Sprintf())#5834
annrpom merged 3 commits intocockroachdb:masterfrom
annrpom:panic-lint-rule

Conversation

@annrpom
Copy link
Contributor

@annrpom annrpom commented Mar 9, 2026

See individual commits for details.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@annrpom annrpom force-pushed the panic-lint-rule branch 6 times, most recently from c03e87b to 41e97bb Compare March 10, 2026 01:26
Add a lint check that disallows panic(fmt.Sprintf(...)) in favor of
panic(errors.AssertionFailedf(...)). Using errors.AssertionFailedf
ensures panic messages are not redacted in CockroachDB logs and include
proper stack traces. The rule supports a lint:ignore PanicFmtSprintf
directive for cases where the pattern is intentionally retained.

Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
@annrpom annrpom force-pushed the panic-lint-rule branch 2 times, most recently from 9d214a3 to 7034608 Compare March 11, 2026 15:24
@annrpom annrpom marked this pull request as ready for review March 11, 2026 17:56
@annrpom annrpom requested a review from a team as a code owner March 11, 2026 17:56
@annrpom annrpom requested a review from RaduBerinde March 11, 2026 17:56
return buf.String()
default:
panic(fmt.Sprintf("unknown command: %s", td.Cmd))
panic(errors.AssertionFailedf("unknown command: %s", td.Cmd))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you can ask Claude to change these kind of panics to t.Fatalf()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

annrpom and others added 2 commits March 11, 2026 20:52
…(...))

Mechanically replace all instances of panic(fmt.Sprintf(...)) with
panic(errors.AssertionFailedf(...)). The errors.AssertionFailedf function
creates structured errors with stack traces, which is preferable to
unstructured panic strings.

This is a mechanical conversion with no changes to the panic arguments
themselves. A follow-up commit wraps safe diagnostic arguments with
errors.Safe() so they appear in redacted crash reports.

Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
…sh reports

For panic messages using errors.AssertionFailedf, arguments are redacted
by default in CockroachDB crash reports. Wrap safe diagnostic arguments
(internal identifiers, counts, sizes, enum values) with errors.Safe() so
they appear in redacted reports, while leaving user keys and values
unwrapped to prevent PII leaks.

Also add SafeFormat/String implementations for interleavePos,
compactionKind, CompactionState, and vfs.OpType so these types are
self-formatting as safe values.

Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
@annrpom
Copy link
Contributor Author

annrpom commented Mar 12, 2026

TFTR! ('-')7

@annrpom annrpom merged commit ac5c1b0 into cockroachdb:master Mar 12, 2026
9 checks passed
@annrpom annrpom deleted the panic-lint-rule branch March 12, 2026 14:20
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