Skip to content

Cause - Last error with stack #173

Description

@marczahn

Hi,

Let's assume we have some nested errors:

function sthBuiltInWhichReturnsAPlainError() error {
    return someBuiltErrorWithoutStack
}

func customFunctionWhichWrapsErrors() error {
    err := sthBuiltInWhichReturnsAPlainError()
    if err != nil {
        return errors.Wrap(err, "something happened")
    }
}

err := customFunctionWhichWrapsErrors()
errors.Cause(err) // <- Here I get the someBuiltErrorWithoutStack which has no stack

I would like to have the "last" error which has a stack. In this case it would be the one that is returned by customFunctionWhichWrapsErrors. But when I call errors.Cause I get the someBuiltErrorWithoutStack since this is the last one in the nesting.

Is this somehow possible without writing custom code?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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