Skip to content

Attach existing frames from an error to a new error without wrapping #59

@prashantv

Description

@prashantv

Errors are not always wrapped where the underlying cause is available via Unwrap -- this is common to avoid implementation detail leakages across API boundaries, to avoid callers depending on specific internal errors via errors.Is or errors.As.

However, this also loses any traces from the underlying errors, and traces aren't intended for APIs but debuggability. This is pretty common when Errorf is used with %v instead of %w. Ideally, we'd have some way to maintain the trace in these cases.

Example API to start the discussion:

if err := [...]; err != nil {
  return WithTrace(err).Errorf("foo: %v", err)
}

or

err := [...]
if errors.Is(err, fs.ErrNotExist) {
  return WithTrace(err).Wrap(errUserNotFound)
}

From an API perspective, we should avoid an API that takes 2 error arguments where one's used for the underlying trace, and the other is the returned error, as it's too easy to mixup the arguments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions