Skip to content

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

@westwin

Description

@westwin

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
}

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