Skip to content

fix: do not panic when logging typed-nil wrapper errors - #61

Open
josuegiron wants to merge 1 commit into
masterfrom
fix/codederror-typed-nil
Open

josuegiron wants to merge 1 commit into
masterfrom
fix/codederror-typed-nil

Conversation

@josuegiron

Copy link
Copy Markdown
Member

Summary

Logging a typed-nil error whose Unwrap or Error dereferences its receiver panicked in the coded-error walk (internal/codederror) or when it was the message argument. Plain slog writes <nil> for such a value.

  • The walk stops a branch at a nil pointer without calling Unwrap.
  • New internal codederror.Text calls Error() and writes a panic as slog does: <nil> for a nil pointer, !PANIC: <value> otherwise. Used for the message and the group's text.

Verification

gofmt -l ., go vet ./..., go test -race ./..., govulncheck ./.... Tests cover the typed nil as an attribute, in a group, behind fmt.Errorf and errors.Join, joined with a coded error, and as the package-level message. BenchmarkValidateArgs: same bytes and allocations before and after.

🤖 Generated with Claude Code

The coded-error walk called Unwrap on a nil pointer and the message path
called Error on it; both panic for types that dereference the receiver.
Stop the walk at nil pointers and write panicking Error results as slog
does (<nil> or !PANIC).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant