entry: allow function-backed error fields - #1579
Merged
Merged
Conversation
Treat values implementing error as supported fields before checking their underlying kind. This allows function-backed error implementations to be added through WithError, WithField, and WithFields, matching formatter behavior that renders error values through Error(), while continuing to reject unsupported function values. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The utility was skipping WithError as intermediate; wrap the logger's WithError method instead. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
There was a problem hiding this comment.
Pull request overview
This PR aligns WithError behavior across Entry, Logger, and package-level helpers, and updates field validation so values implementing error are accepted even when their underlying kind is a function (e.g., function-backed error implementations). This brings WithError, WithField, and WithFields in line with formatter behavior while still rejecting unsupported non-error function values.
Changes:
- Route
Entry.WithErrorand package-levelWithErrorthrough the existingWithError/WithFieldpaths for consistent behavior. - Update
Entry.addFieldto treaterror-implementing values as supported before applying function-kind rejection. - Simplify and strengthen tests to assert consistent acceptance/rejection and JSON formatting across
WithError,WithField, andWithFields.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| exported.go | Makes package-level WithError delegate to std.WithError for consistency with logger behavior. |
| entry.go | Unifies Entry.WithError with WithField and adjusts field validation to allow function-backed error values. |
| entry_test.go | Updates tests to validate consistent acceptance/rejection and formatting of error vs function values across APIs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
entry: allow function-backed error fields
Treat values implementing error as supported fields before checking their
underlying kind.
This allows function-backed error implementations to be added through
WithError, WithField, and WithFields, matching formatter behavior that renders
error values through Error(), while continuing to reject unsupported function
values.
logger: WithError: wrap logger.WithError for consistency
The utility was skipping WithError as intermediate; wrap the logger's
WithError method instead.
Performance remains identical, or even slightly improved for some cases;