Sub returns an error containing root as its root and taking all other metadata (stack trace, detail, message, and data items) from err. Sub returns nil when either root or err is nil. Use this when you need to substitute a new root error in place of an existing error that may already hold a stack
(root, err error)
| 174 | // of an existing error that may already hold a stack trace |
| 175 | // or other metadata. |
| 176 | func Sub(root, err error) error { |
| 177 | if wrapper, ok := err.(wrapperError); ok && root != nil { |
| 178 | wrapper.root = Root(root) |
| 179 | wrapper.msg = root.Error() |
| 180 | root = wrapper |
| 181 | } |
| 182 | if err == nil { |
| 183 | return nil |
| 184 | } |
| 185 | return Wrap(root, err.Error()) |
| 186 | } |