diff --git a/pkg/private/serrors/errors_test.go b/pkg/private/serrors/errors_test.go index f62fce5cf2..803cd8c422 100644 --- a/pkg/private/serrors/errors_test.go +++ b/pkg/private/serrors/errors_test.go @@ -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) { @@ -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)) diff --git a/pkg/private/serrors/stack.go b/pkg/private/serrors/stack.go index 08ffca5f3a..b8a4f843a6 100644 --- a/pkg/private/serrors/stack.go +++ b/pkg/private/serrors/stack.go @@ -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 } diff --git a/pkg/private/serrors/testdata/error-list.log b/pkg/private/serrors/testdata/error-list.log index 7cff5bbf1a..83775ffe9e 100644 --- a/pkg/private/serrors/testdata/error-list.log +++ b/pkg/private/serrors/testdata/error-list.log @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/pkg/private/serrors/testdata/error-with-context.log b/pkg/private/serrors/testdata/error-with-context.log index 807fc51f6e..d341a89306 100644 --- a/pkg/private/serrors/testdata/error-with-context.log +++ b/pkg/private/serrors/testdata/error-with-context.log @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/pkg/private/serrors/testdata/goroutine.err b/pkg/private/serrors/testdata/goroutine.err new file mode 100644 index 0000000000..a173b05f51 --- /dev/null +++ b/pkg/private/serrors/testdata/goroutine.err @@ -0,0 +1 @@ +msg \ No newline at end of file diff --git a/pkg/private/serrors/testdata/goroutine.log b/pkg/private/serrors/testdata/goroutine.log new file mode 100644 index 0000000000..b7d2540846 --- /dev/null +++ b/pkg/private/serrors/testdata/goroutine.log @@ -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"} \ No newline at end of file diff --git a/pkg/private/serrors/testdata/new-with-context.log b/pkg/private/serrors/testdata/new-with-context.log index 0779fccc14..101e6a9aa1 100644 --- a/pkg/private/serrors/testdata/new-with-context.log +++ b/pkg/private/serrors/testdata/new-with-context.log @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/pkg/private/serrors/testdata/wrapped-error.log b/pkg/private/serrors/testdata/wrapped-error.log index ccf49307c0..d9f2212c13 100644 --- a/pkg/private/serrors/testdata/wrapped-error.log +++ b/pkg/private/serrors/testdata/wrapped-error.log @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/pkg/private/serrors/testdata/wrapped-string.log b/pkg/private/serrors/testdata/wrapped-string.log index dc7cd3bafc..5a3ead2298 100644 --- a/pkg/private/serrors/testdata/wrapped-string.log +++ b/pkg/private/serrors/testdata/wrapped-string.log @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/pkg/private/serrors/testdata/wrapped-with-string.log b/pkg/private/serrors/testdata/wrapped-with-string.log index aba98048bd..137aa378e1 100644 --- a/pkg/private/serrors/testdata/wrapped-with-string.log +++ b/pkg/private/serrors/testdata/wrapped-with-string.log @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file