-
Notifications
You must be signed in to change notification settings - Fork 18k
log/slog: nil pointer dereference when printing nil regexp #61648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I’m assuming the crash is linked to the new regexp implementation of MarshalText: + +// MarshalText implements [encoding.TextMarshaler]. The output +// matches that of calling the [Regexp.String] method. +// +// Note that the output is lossy in some cases: This method does not indicate +// POSIX regular expressions (i.e. those compiled by calling [CompilePOSIX]), or +// those for which the [Regexp.Longest] method has been called. +func (re *Regexp) MarshalText() ([]byte, error) { + return []byte(re.String()), nil +} + +// UnmarshalText implements [encoding.TextUnmarshaler] by calling +// [Compile] on the encoded value. +func (re *Regexp) UnmarshalText(text []byte) error { + newRE, err := Compile(string(text)) + if err != nil { + return err + } + *re = *newRE + return nil +} Logging is a place where we really want to have nil values printed (indeed, this can be valuable for program debugging), so my sense is that |
cc @jba |
Agreed, slog should catch panics when formatting, like the I changed the title of this issue to reflect that. |
Change https://go.dev/cl/514135 mentions this issue: |
Fixes golang#61648 Change-Id: I6b7f4948ca89142a358d74624607daf42ea8b304 Reviewed-on: https://go-review.googlesource.com/c/go/+/514135 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Andy Pan <panjf2000@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Jonathan Amsterdam <jba@google.com>
… a panic, Fixes [#61648](golang/go#61648)
Fixes golang#61648 Change-Id: I6b7f4948ca89142a358d74624607daf42ea8b304 Reviewed-on: https://go-review.googlesource.com/c/go/+/514135 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Andy Pan <panjf2000@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Jonathan Amsterdam <jba@google.com>
Fixes golang#61648 Change-Id: I6b7f4948ca89142a358d74624607daf42ea8b304 Reviewed-on: https://go-review.googlesource.com/c/go/+/514135 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Andy Pan <panjf2000@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Jonathan Amsterdam <jba@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes – this is indeed a regression from using go1.20 + exp/slog
What did you do?
Log in a simple nil value using slog
https://go.dev/play/p/jAg4xDbs4sn?v=gotip
What did you expect to see?
A formatted nil line, as per https://go.dev/play/p/b7Vjf1L09sC
What did you see instead?
Crash, with nil pointer deref
The text was updated successfully, but these errors were encountered: