Skip to content

Commit

Permalink
serrors: remove bottom of stacktrace, test without lineno
Browse files Browse the repository at this point in the history
Remove the botton of stacktraces attached by serrors, as this
always a relatively uninteresting line in the runtime (currently,
"runtime.goexit src/runtime/asm_amd64.s:1650").

For the serrors tests, strip the file/line number referring to
the go test framework, to avoid false negatives when running
tests with slightly different go SDK version.
  • Loading branch information
matzf committed Mar 25, 2024
1 parent 2798312 commit 5153455
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 11 deletions.
16 changes: 12 additions & 4 deletions pkg/private/serrors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ func TestEncoding(t *testing.T) {
},
goldenFileBase: "testdata/error-list",
},
"goroutine stacktrace": {
err: func() error {
errs := make(chan error)
go func() {
errs <- serrors.New("msg")
}()
return <-errs
}(),
goldenFileBase: "testdata/goroutine",
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
Expand Down Expand Up @@ -393,10 +403,8 @@ func sanitizeLog(log []byte) []byte {
{`[^\s"]*pkg/private/serrors_test.Test`, "pkg/private/serrors/go_default_test_test.Test"},
// serrors package
{`[^\s"]*/pkg/private/serrors`, "pkg/private/serrors"},
// go sdk
{`[^\s"]*/src/testing`, "src/testing"},
// go runtime
{`[^\s"]*/src/runtime`, "src/runtime"},
// go sdk: strip file name and line number to reduce churn
{`[^\s"]*/src/testing[\w/.]*:\d*`, "gosdk"},
} {
re := regexp.MustCompile(replacer.pattern)
log = re.ReplaceAll(log, []byte(replacer.replace))
Expand Down
2 changes: 1 addition & 1 deletion pkg/private/serrors/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func callers() *stack {
const depth = 32
var pcs [depth]uintptr
n := runtime.Callers(3, pcs[:])
var st stack = pcs[0:n]
var st stack = pcs[0 : n-1] // skip bottom runtime.goexit at bottom of each stack
return &st
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/private/serrors/testdata/error-list.log
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"err":[{"ctx1":"val1","msg":"test err","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:227","testing.tRunner src/testing/testing.go:1595","runtime.goexit src/runtime/asm_amd64.s:1650"]},{"msg":"test err2","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:228","testing.tRunner src/testing/testing.go:1595","runtime.goexit src/runtime/asm_amd64.s:1650"]}],"level":"info","msg":"Failed to do thing"}
{"err":[{"ctx1":"val1","msg":"test err","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:227","testing.tRunner gosdk"]},{"msg":"test err2","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:228","testing.tRunner gosdk"]}],"level":"info","msg":"Failed to do thing"}
2 changes: 1 addition & 1 deletion pkg/private/serrors/testdata/error-with-context.log
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"err":{"msg":{"msg":"simple err","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:222","testing.tRunner src/testing/testing.go:1595","runtime.goexit src/runtime/asm_amd64.s:1650"]},"someCtx":"someValue"},"level":"info","msg":"Failed to do thing"}
{"err":{"msg":{"msg":"simple err","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:222","testing.tRunner gosdk"]},"someCtx":"someValue"},"level":"info","msg":"Failed to do thing"}
1 change: 1 addition & 0 deletions pkg/private/serrors/testdata/goroutine.err
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
msg
1 change: 1 addition & 0 deletions pkg/private/serrors/testdata/goroutine.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"err":{"msg":"msg","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding.func2.1 pkg/private/serrors/errors_test.go:236"]},"level":"info","msg":"Failed to do thing"}
2 changes: 1 addition & 1 deletion pkg/private/serrors/testdata/new-with-context.log
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"err":{"k0":"v0","k1":1,"msg":"err msg","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:191","testing.tRunner src/testing/testing.go:1595","runtime.goexit src/runtime/asm_amd64.s:1650"]},"level":"info","msg":"Failed to do thing"}
{"err":{"k0":"v0","k1":1,"msg":"err msg","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:191","testing.tRunner gosdk"]},"level":"info","msg":"Failed to do thing"}
2 changes: 1 addition & 1 deletion pkg/private/serrors/testdata/wrapped-error.log
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"err":{"cause":{"msg":"msg cause","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:215","testing.tRunner src/testing/testing.go:1595","runtime.goexit src/runtime/asm_amd64.s:1650"]},"k0":"v0","k1":1,"msg":{"msg":"msg error","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:214","testing.tRunner src/testing/testing.go:1595","runtime.goexit src/runtime/asm_amd64.s:1650"]}},"level":"info","msg":"Failed to do thing"}
{"err":{"cause":{"msg":"msg cause","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:215","testing.tRunner gosdk"]},"k0":"v0","k1":1,"msg":{"msg":"msg error","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:214","testing.tRunner gosdk"]}},"level":"info","msg":"Failed to do thing"}
2 changes: 1 addition & 1 deletion pkg/private/serrors/testdata/wrapped-string.log
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"err":{"cause":{"msg":"msg cause","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:197","testing.tRunner src/testing/testing.go:1595","runtime.goexit src/runtime/asm_amd64.s:1650"]},"k0":"v0","k1":1,"msg":"msg error"},"level":"info","msg":"Failed to do thing"}
{"err":{"cause":{"msg":"msg cause","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:197","testing.tRunner gosdk"]},"k0":"v0","k1":1,"msg":"msg error"},"level":"info","msg":"Failed to do thing"}
2 changes: 1 addition & 1 deletion pkg/private/serrors/testdata/wrapped-with-string.log
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"err":{"cause":{"cause_ctx_key":"cause_ctx_val","msg":"msg cause","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:206","testing.tRunner src/testing/testing.go:1595","runtime.goexit src/runtime/asm_amd64.s:1650"]},"k0":"v0","k1":1,"msg":"msg error"},"level":"info","msg":"Failed to do thing"}
{"err":{"cause":{"cause_ctx_key":"cause_ctx_val","msg":"msg cause","stacktrace":["pkg/private/serrors/go_default_test_test.TestEncoding pkg/private/serrors/errors_test.go:206","testing.tRunner gosdk"]},"k0":"v0","k1":1,"msg":"msg error"},"level":"info","msg":"Failed to do thing"}

0 comments on commit 5153455

Please sign in to comment.