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

Add attach and mask functions for joining errors in a different way #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jsternberg
Copy link

The Attach and Mask functions create a new error node that returns the error message from one node, but creates a structure where the additional errors are in the error chain and can be discovered with errors.Is and errors.As.

The `Attach` and `Mask` functions create a new error node that returns
the error message from one node, but creates a structure where the
additional errors are in the error chain and can be discovered with
`errors.Is` and `errors.As`.

Signed-off-by: Jonathan A. Sternberg <[email protected]>
@jsternberg
Copy link
Author

There's two usages I envision with the above functions.

  1. An alternative to the current stack trace implementation. Stack can be built off of Attach instead of collapsible error and I think it would be easier to understand.
  2. A way of integrating errdefs with applications that don't use errdefs natively. You can take an existing error and use errdefs.Mask(err, errdefs.ErrInvalidArgument) and that will add invalid argument to the error chain so errgrpc works appropriately, but won't change the underlying message. This isn't possible with errors.Join or fmt.Errorf.

@dmcgowan
Copy link
Member

If we add these functions in, we should make sure use of them in stack and errgrpc package to ensure the interface aligns with what we need there.

@AkihiroSuda
Copy link
Member

ping @jsternberg

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.

3 participants