Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
prashantv opened this issue Nov 29, 2023 · 1 comment
Open

Comments

@prashantv
Copy link
Contributor

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.

@abhinav
Copy link
Contributor

abhinav commented Nov 29, 2023

If we do something like this, we'll may want to define a cross-repo interface contract for extracting trace information (similar to pkg/errors' interface{ Stacktrace() errors.StackTrace }) from an error.

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

No branches or pull requests

2 participants