Global stack trace can be incorrect if another error is wrapped before the first one is logged
morningvera opened this issue · 1 comments
morningvera commented
Describe the bug
Because error wrapping just wraps a ptr to the global val, we can see errors in the stack traces if multiple errors are wrapped before printing or logging. Basically every time the global is wrapped, it ends up resetting the stack for every error that wrapped it before.
To Reproduce
Observe that the root stack trace for err1 is incorrect in this case. It will be the same as err2 (apart from the inserted wrap frame).
err1 := eris.Wrap(ErrBadRequest, "test 1")
err2 := eris.Wrap(ErrBadRequest, "test 2")
fmt.Printf("%+v\n", err1)
fmt.Printf("%+v\n", err2)
Expected behavior
Wrapping global vals should produce consistent stack traces for all errors. We probably need to deep copy the global so that wrapping it produces an error that can't be interfered with.
morningvera commented
fixed