This repository has been archived by the owner on Dec 1, 2021. It is now read-only.
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.
WithMessage appends message after associated stack traces instead of before #102
Open
Description
After amending an error using errors.WithMessage, printing the error with %+v
prints the extra information after the stack trace instead of with the original message. For example:
package main
import (
"log"
"github.com/pkg/errors"
)
func a() error {
return errors.New("error details")
}
func b() error {
if err := a(); err != nil {
return errors.WithMessage(err, "additional details")
}
return nil
}
func main() {
if err := b(); err != nil {
log.Fatalf("%+v", err)
}
}
This prints:
2017/02/06 14:34:13 error details
main.a
.../example.go:10
main.b
.../example.go:14
main.main
.../example.go:21
runtime.main
/usr/local/Cellar/go/1.7.4_2/libexec/src/runtime/proc.go:183
runtime.goexit
/usr/local/Cellar/go/1.7.4_2/libexec/src/runtime/asm_amd64.s:2086
additional details
exit status 1
As mentioned in #75, it seems like it would be more helpful to include the additional information with original error message. When using %v
with the same example, it prints messages in this way now:
2017/02/06 14:33:32 additional details: error details
exit status 1
Metadata
Assignees
Labels
No labels
Activity