Skip to content

feat: v0.2.0 — add ErrAny for recover() payloads#2

Merged
maxence2997 merged 7 commits into
mainfrom
feat/v0.2.0-err-any
May 6, 2026
Merged

feat: v0.2.0 — add ErrAny for recover() payloads#2
maxence2997 merged 7 commits into
mainfrom
feat/v0.2.0-err-any

Conversation

@maxence2997
Copy link
Copy Markdown
Owner

Summary

  • Add ErrAny(v any) []zap.Field for non-error panic recovery values (recover() returns any).
  • Clarify in README the relationship between ecsf.Err, single-field error helpers, and zap.Error(err) when paired with the ecszap encoder.

Why

Surfaced from streaming-observer dogfooding of v0.1.0:

  1. Panic recovery code had to manually do fmt.Sprint(recovered) + fmt.Sprintf("%T", recovered) because Err(error) doesn't accept any. ErrAny removes that boilerplate and delegates to Err when the value is actually an error.
  2. The README didn't make clear that zap.Error(err) under ecszap already produces ECS-shaped output, almost causing unnecessary scope creep when migrating call sites.

API

// Returns nil for nil input. Delegates to Err() when v satisfies error
// (so stack_trace works for StackTracer errors). Otherwise emits
// error.message = fmt.Sprint(v), error.type = fmt.Sprintf("%T", v).
func ErrAny(v any) []zap.Field

Typical panic recovery:

defer func() {
    if r := recover(); r != nil {
        fields := ecsf.ErrAny(r)
        fields = append(fields, ecsf.ErrorStackTrace(debug.Stack()))
        logger.Error("panic recovered", fields...)
    }
}()

Test plan

  • make check passes (fmt + lint + race-detector test)
  • New tests cover: nil, plain error, StackTracer error, string, int, struct
  • CI green

1.recover() returns any not error -> ErrAny accepts any
2.error input could share Err logic -> delegate when err
3.nil input would emit empty fields -> return nil safely
1.Reader saw Err() as redundant under ecszap -> add subsection
2.Coverage table missed ErrAny -> bump to ~117 helpers
3.CHANGELOG had only Unreleased -> log v0.2.0 entry
Copilot AI review requested due to automatic review settings May 6, 2026 00:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new zap subpackage helper to extract ECS error.* fields from recover() payloads (typed as any), and updates documentation to clarify how ecsfields error helpers relate to zap.Error(err) when using the ecszap encoder.

Changes:

  • Introduce ErrAny(v any) to emit ECS error fields for non-error panic payloads while delegating to Err(err) when possible.
  • Add unit tests covering ErrAny for nil, error, stack-tracer error, and several non-error payload types.
  • Update README, ECS coverage docs, and CHANGELOG for v0.2.0 and the new helper.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
zap/error.go Adds ErrAny(any) helper for recover() payloads and documents intended usage.
zap/error_test.go Adds tests validating ErrAny behavior across error and non-error inputs.
README.md Updates coverage counts and documents how to choose between ecsf.Err* helpers and zap.Error.
docs/ecs-coverage.md Updates coverage matrix to include ErrAny() and bumps version label/count.
CHANGELOG.md Adds v0.2.0 entry describing ErrAny and the documentation clarification.

Comment thread zap/error.go
1.recover(typedNilErr) would panic in err.Error() -> typed-nil check
2.Lost type info on nil error harmed debugging -> emit error.type
3.Defense covers all nillable kinds not just Ptr -> reflect.Kind switch
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread README.md Outdated
1.pkg/errors users got message+type but no stack -> add interface
2.Two interfaces share extraction logic -> extractStackTrace helper
3.GoDoc warned pkg/errors unsupported -> update to both supported
1.zap.Error stack was overstated -> qualify with StackTracer
2.Err now also reads pkg/errors -> note dual interface support
3.CHANGELOG missed pkg/errors and typed-nil -> add entries
1.Coverage said StackTrace bytes only -> note both interfaces
2.pkg/errors users had no signal in coverage -> name it
Copilot AI review requested due to automatic review settings May 6, 2026 02:10
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Comment thread zap/error.go Outdated
Comment thread zap/error.go Outdated
Comment thread zap/error.go Outdated
Comment thread README.md
Comment thread README.md
Comment thread docs/ecs-coverage.md Outdated
Comment thread CHANGELOG.md Outdated
1.errors.StackTrace clashed visually with stdlib -> pkgerrors prefix
2.errors.New/Wrap reads as stdlib in package doc -> pkgerrors prefix
3.Markdown lacks import context too -> use same prefix everywhere
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@maxence2997 maxence2997 merged commit faabd15 into main May 6, 2026
6 checks passed
@maxence2997 maxence2997 deleted the feat/v0.2.0-err-any branch May 6, 2026 02:35
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.

2 participants