]> Cypherpunks.ru repositories - gostls13.git/commit
src/log/slog: JSONHandler checks if error implements json.Marshaler
authorJonathan Amsterdam <jba@google.com>
Wed, 29 Mar 2023 13:57:33 +0000 (09:57 -0400)
committerJonathan Amsterdam <jba@google.com>
Wed, 29 Mar 2023 20:46:52 +0000 (20:46 +0000)
commit93b3035dbbcd21c1d0538142cba4e7f79631e7a2
treef87cb7fc3ddc6e417b5e53de3ef2e294745dde70
parent1844b541664525a0298603154915e74ca742e406
src/log/slog: JSONHandler checks if error implements json.Marshaler

json.Marshal doesn't do what one might hope on many Go error values.
Errors created with errors.New marshal as "{}". So JSONHandler treats
errors specially, calling the Error method instead of json.Marshal.

However, if the error happens to implement json.Marshaler, then
JSONHandler should call json.Marshal after all. This CL makes
that change.

Change-Id: I2154246b2ca8fa13d4f6f1256f7a16aa98a8c24a
Reviewed-on: https://go-review.googlesource.com/c/go/+/480155
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
src/log/slog/json_handler.go
src/log/slog/json_handler_test.go