go-simpler / sloglint

🪵 Ensure consistent code style when using log/slog
https://go-simpler.org/sloglint
Mozilla Public License 2.0
75 stars 5 forks source link

Report using `error` without key #39

Closed maratori closed 2 months ago

maratori commented 2 months ago

slog doesn't catch the following common mistake

err := errors.New("failed")
// wrong
logger.Error("Something went wrong", err) // "!BADKEY":"failed"
// correct
logger.Error("Something went wrong", "error", err) // "error":"failed"

err may be any type except slog.Attr. So ideally, need to validate any type. But the most common is error, and need to validate at least it.

tmzane commented 2 months ago

Hello,

Looks like it is already reported at https://github.com/golang/go/issues/65740 and about to get fixed.