Error Not Logged With Object (ARCH5159)
Key go.logging.error-not-logged · Severity warning · Category logging
Logging an error with only a constant message while dropping the error value itself discards the root-cause chain and any wrapped context. The error object should always be attached as a log field.
Incorrect
Section titled “Incorrect”func sync(log *slog.Logger) { if err := pull(); err != nil { log.Error("sync failed") }}Correct
Section titled “Correct”func sync(log *slog.Logger) { if err := pull(); err != nil { log.Error("sync failed", "err", err) }}Attach the error as a field ("err", err) on the log call to preserve the root cause.