feat!: v0.3.0 — Err / ErrAny return single inline zap.Field#3
Merged
Conversation
1.[]Field broke inline log call style -> return one Field 2.zap.Inline preserves flat dotted keys -> output unchanged 3.nil input would force conditional append -> return zap.Skip
There was a problem hiding this comment.
Pull request overview
This PR introduces a breaking API change in the zap/ subpackage: Err(err) and ErrAny(v) now return a single inline zapcore.Field (via zap.Inline) instead of []zapcore.Field, while keeping the emitted ECS error.* keys and flat JSON output shape the same.
Changes:
- Refactor
Err/ErrAnyto return a single inlinezapcore.Fieldbacked byzapcore.ObjectMarshaler. - Rewrite error tests to assert emitted encoder output (via
zapcore.NewMapObjectEncoder) rather than inspecting field slices. - Update example + docs + changelog to reflect the new inline-call style and
zap.Skip()nil behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
zap/error.go |
Switch Err/ErrAny to zap.Inline + marshalers, and return zap.Skip() on nil input. |
zap/error_test.go |
Update tests to validate encoded output for inline fields and skip behavior. |
example/main.go |
Update example usage to pass ecsf.Err(err) inline (no slice append/splat). |
docs/related-projects.md |
Adjust guidance table to remove ... splat usage for Err/ErrAny. |
docs/ecs-coverage.md |
Update coverage notes to reflect new return types and inline behavior. |
CHANGELOG.md |
Document the breaking change and provide migration snippet. |
1.Err(typedNil) panicked in errMarshaler.Error -> guard moved 2.Two marshalers checked typed-nil -> single check in errMarshaler 3.Tests hard-coded *errors.errorString -> derive via %T
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
zap/error.go:56
- The
Errdoc comment sayserror.messageis alwayserr.Error(), but typed-nil errors intentionally emiterror.message = "<nil>"without callingError(). Consider adjusting the bullet list to reflect this exception so the docs match the actual behavior.
// Err returns a single inline zap.Field that emits ECS error.* fields:
//
// - error.message: always (err.Error())
// - error.type: always (fmt.Sprintf("%T", err))
// - error.stack_trace: if any error in the chain implements one of the
1.errors.As matched typed-nil tracer -> StackTrace panicked 2.Fix only safe up to first typed-nil -> document limitation 3.Wrapped typed-nil scenario lacked test -> add safeWrapper case
1.v0.3.0 returns single inline Field -> wording contradicted code 2.Multi-field tag added no info -> describe behavior directly
1.Snippet used unqualified names -> add ecsf prefix 2.Mentioned no import context -> note the recommended alias
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.
Summary
BREAKING CHANGE.
Err(err)andErrAny(v)now return a singlezap.Field(inline) instead of[]zap.Field. Output JSON is unchanged — same flat dotted ECS keys.Why
Surfaced from streaming-observer dogfooding (O4 in the v0.2.0 dogfood report):
The
[]zap.Fieldreturn type forces callers to break inline log call style and fight withprealloclint:v0.xallows breaking changes, so the cleaner API wins over a parallelErrFieldhelper that would split the API surface.How
Err(err) zap.Fieldreturnszap.Inline(errMarshaler{err: err})— a single Field whoseMarshalLogObjectwriteserror.message/error.type/error.stack_tracedirectly into the encoder.ErrAny(v) zap.Fieldmirrors the structure witherrAnyMarshaler(handles typed-nil, non-error fallback, then delegates toerrMarshaler).zap.Skip()when input is nil — the field is no-op when added, so unconditional inline use is safe.zap.Inlineflattens the marshaler's keys at the current namespace, so output is identical to the v0.2.0 multi-field shape (no nesting, no dot/object difference).Test plan
make checkpasses (fmt + lint + race-detector test)zapcore.NewMapObjectEncoderoutput (whichzap.Inlineflattens into viaAddTo)