Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ func (c Context) Err(err error) Context {
if c.l.stack && ErrorStackMarshaler != nil {
switch m := ErrorStackMarshaler(err).(type) {
case nil:
return c // do nothing with nil errors
// ErrorStackMarshaler returned nil — the error has no stack trace to
// attach. Fall through and still log the error via AnErr below.
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline comment says “Fall through” inside a Go type-switch, but there is no fallthrough statement here. This wording can be misleading since “fallthrough” has a specific meaning in Go switches; consider rephrasing to something like “do nothing here; continue after the switch and still log the error via AnErr below.”

Suggested change
// attach. Fall through and still log the error via AnErr below.
// attach. Do nothing here; continue after the switch and still log
// the error via AnErr below.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

@IDisposable IDisposable Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the language from the other PR's change in event.go. Consistency rules (or I could change both in this PR, what say you @rs)?

case LogObjectMarshaler:
c = c.Object(ErrorStackFieldName, m)
case error:
Expand Down
5 changes: 4 additions & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ func TestContext_ErrWithNilStackMarshaler(t *testing.T) {
log.Info().Msg("test message")

got := decodeIfBinaryToString(buf.Bytes())
want := `{"level":"info","message":"test message"}` + "\n" // No stack or error field because stack marshaler returned nil
// When ErrorStackMarshaler returns nil (no stack trace available for this
// error), Err() must still log the error value via AnErr. Without a stack
// field, the output is the same as if Stack() had not been called.
want := `{"level":"info","error":"test error","message":"test message"}` + "\n"
if got != want {
t.Errorf("Context.Err() with nil stack marshaler = %q, want %q", got, want)
}
Expand Down
Loading