Conversation
|
Not LGTM sorry. Do we need a field on withMessage? Can't you do type assertion instead? |
|
Essentially, there are two use cases we want to meet here.
If you use type assertion to accomplish this, you might do the type assertion in the func (w *withStack) Format(s fmt.State, verb rune) {
switch verb {
case 'v':
if s.Flag('+') {
withMessageWrapper, ok := w.Cause().(*withMessage) // Type Assertion
if ok { // Run this whenever we have a withMessage next in the chain
fmt.Fprintf(s, "%+v\n", withMessageWrapper.Cause())
io.WriteString(s, withMessageWrapper.msg)
w.stack.Format(s, verb)
} else { // Run this for anything else next in the chain
fmt.Fprintf(s, "%+v", w.Cause())
w.stack.Format(s, verb)
}
return
}
fallthrough
case 's':
io.WriteString(s, w.Error())
case 'q':
fmt.Fprintf(s, "%q", w.Error())
}
}This introduces an issue that from that scope there is no way to determine whether the The scenario can easily occur where a pre-existing Maybe that is a viable solution? Is there a scenario where a |
|
Does it help to use |
|
What is the status of this PR? Does the comment above helped the discussion? |
Fixes #102
With these changes, when using a plain
withMessage(), we'll print the additional message in front of the original error message, above the stack trace. This maintains the correct ordering when an error is beingWrap()'d, printing the message + second stack trace after the first message + stack trace.