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

Wrap an external customized error end up as a rootErr ? #120

Open
westwin opened this issue Mar 20, 2023 · 0 comments
Open

Wrap an external customized error end up as a rootErr ? #120

westwin opened this issue Mar 20, 2023 · 0 comments

Comments

@westwin
Copy link

westwin commented Mar 20, 2023

according to the document of Wrap(),

// Wrap adds additional context to all error types while maintaining the type of the original error.
//
// This method behaves differently for each error type. For root errors, the stack trace is reset to the current
// callers which ensures traces are correct when using global/sentinel error values. Wrapped error types are simply
// wrapped with the new context. For external types (i.e. something other than root or wrap errors), this method
// attempts to unwrap them while building a new error chain. If an external type does not implement the unwrap
// interface, it flattens the error and creates a new root error from it before wrapping with the additional
// context.

it says for external types, it attempts to unwrap the (the unwrap interface), but I didn't find the Unwrap() is called

btw, what is the best practice to wrap an external error, say
type MyError struct {
Code int // error code
}

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

1 participant