x/exp/slog: TextHandler panics on nil arg #58652
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
When using attr to output nil, the text handler gets panic, while the json handler does not, expecting the correct null output
What did you see instead?
=== RUN TestTextHandler
{"time":"2023-02-23T10:51:38.906392+08:00","level":"INFO","msg":"json msg1","key":"str","err":null}
{"time":"2023-02-23T10:51:38.906612+08:00","level":"INFO","msg":"json msg2","key":"str","err":null}
--- FAIL: TestTextHandler (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x98 pc=0x11539a0]
goroutine 4 [running]:
testing.tRunner.func1.2({0x11725e0, 0x12c28e0})
/usr/local/go/src/testing/testing.go:1396 +0x24e
testing.tRunner.func1()
/usr/local/go/src/testing/testing.go:1399 +0x39f
panic({0x11725e0, 0x12c28e0})
/usr/local/go/src/runtime/panic.go:884 +0x212
golang.org/x/exp/slog.byteSlice({0x0?, 0x0})
/Users/gowork/gx/vendor/golang.org/x/exp/slog/text_handler.go:130 +0x80
golang.org/x/exp/slog.appendTextValue(0xc000135708, {0x5?, {0x0?, 0x0?}})
/Users/gowork/gx/vendor/golang.org/x/exp/slog/text_handler.go:109 +0x305
golang.org/x/exp/slog.(*handleState).appendValue(0xc000135708, {0x1196f12?, {0x0?, 0x0?}})
/Users/gowork/gx/vendor/golang.org/x/exp/slog/handler.go:532 +0x37
golang.org/x/exp/slog.(*handleState).appendAttr(0xc000135708, {{0x1196f12, 0x3}, {0x0, {0x0, 0x0}}})
/Users/gowork/gx/vendor/golang.org/x/exp/slog/handler.go:468 +0x725
golang.org/x/exp/slog.(*handleState).appendNonBuiltIns.func1({{0x1196f12, 0x3}, {0x0, {0x0, 0x0}}})
/Users/gowork/gx/vendor/golang.org/x/exp/slog/handler.go:327 +0x4f
golang.org/x/exp/slog.Record.Attrs({{0xc0f5d1d36f9de160, 0xf6a35, 0x12cc380}, {0x1197c45, 0x8}, 0x0, {0x0, 0x0}, 0x1158807, {{{0x1196f2d, ...}, ...}, ...}, ...}, ...)
/Users/gowork/gx/vendor/golang.org/x/exp/slog/record.go:100 +0x9e
golang.org/x/exp/slog.(*handleState).appendNonBuiltIns(, {{0xc0f5d1d36f9de160, 0xf6a35, 0x12cc380}, {0x1197c45, 0x8}, 0x0, {0x0, 0x0}, 0x1158807, ...})
/Users/gowork/gx/vendor/golang.org/x/exp/slog/handler.go:326 +0x465
golang.org/x/exp/slog.(*commonHandler).handle(, {{0xc0f5d1d36f9de160, 0xf6a35, 0x12cc380}, {0x1197c45, 0x8}, 0x0, {0x0, 0x0}, 0x1158807, ...})
/Users/gowork/gx/vendor/golang.org/x/exp/slog/handler.go:304 +0x8c8
golang.org/x/exp/slog.(*TextHandler).Handle(_, {{0xc0f5d1d36f9de160, 0xf6a35, 0x12cc380}, {0x1197c45, 0x8}, 0x0, {0x0, 0x0}, 0x1158807, ...})
/Users/gowork/gx/vendor/golang.org/x/exp/slog/text_handler.go:90 +0x58
golang.org/x/exp/slog.(*Logger).logPC(0xc000135dc8, {0x0, 0x0}, 0x1158807, 0x0, {0x1197c45, 0x8}, {0xc000135ee0, 0x4, 0x4})
/Users/gowork/gx/vendor/golang.org/x/exp/slog/logger.go:178 +0x255
golang.org/x/exp/slog.(*Logger).LogDepth(0xc000135dc8, 0x1, 0x100d9ff?, {0x1197c45, 0x8}, {0xc000135ee0, 0x4, 0x4})
/Users/gowork/gx/vendor/golang.org/x/exp/slog/pc.go:26 +0xe8
golang.org/x/exp/slog.(*Logger).Info(...)
/Users/gowork/gx/vendor/golang.org/x/exp/slog/logger.go:193
git.woa.com/sase/gx/glibs/slogx.TestTextHandler(0x0?)
/Users/gowork/gx/glibs/slogx/slog_core_test.go:47 +0x42d
testing.tRunner(0xc0001501a0, 0x11ba030)
/usr/local/go/src/testing/testing.go:1446 +0x10b
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:1493 +0x35f
Process finished with the exit code 1
The text was updated successfully, but these errors were encountered: