Skip to content

Commit

Permalink
pkg/testutils/lint: add a linter rule to block call to debug.Stack()
Browse files Browse the repository at this point in the history
Some of the previous commits addressed the unnecessary redaction of
stack traces by replacing uses of debug.Stack() with debugutil.Stack().
The new function ensures proper handling of redaction.

This commit future-proofs the solution by adding a linter rule to block
future uses of debug.Stack(). The linter error will prompt users to use
debugutil.Stack() instead.

Part of: CRDB-15292
Epic: CRDB-37533
Release note: None
  • Loading branch information
arjunmahishi committed Dec 9, 2024
1 parent 5ff2ff2 commit d4ea2d5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pkg/testutils/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2882,4 +2882,35 @@ func TestLint(t *testing.T) {
}
})

t.Run("TestDebugStack", func(t *testing.T) {
t.Parallel()

excludeFiles := []string{
":!util/debugutil/debugutil.go",
":!server/debug/goroutineui/dump_test.go",
}

cmd, stderr, filter, err := dirCmd(pkgDir, "git", append([]string{
"grep", "-nE", `debug\.Stack\(`, "--", "*.go",
}, excludeFiles...)...)
if err != nil {
t.Fatal(err)
}

if err := cmd.Start(); err != nil {
t.Fatal(err)
}

if err := stream.ForEach(filter, func(s string) {
t.Errorf("\n%s <- forbidden; use 'debugutil.Stack()' instead", s)
}); err != nil {
t.Error(err)
}

if err := cmd.Wait(); err != nil {
if out := stderr.String(); len(out) > 0 {
t.Fatalf("err=%s, stderr=%s", err, out)
}
}
})
}

0 comments on commit d4ea2d5

Please sign in to comment.