generated from logur/integration-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror.go
45 lines (37 loc) · 846 Bytes
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package watermill
import (
"fmt"
"io"
)
// errorWithMessage annotates err with a new message.
// Copied from https://github.com/emperror/errors/blob/acc47e5/errors.go#L169-L231
func errorWithMessage(err error, message string) error {
if err == nil {
return nil
}
return &withMessage{
error: err,
msg: message,
}
}
type withMessage struct {
error error
msg string
}
func (w *withMessage) Error() string { return w.msg + ": " + w.error.Error() }
func (w *withMessage) Cause() error { return w.error }
func (w *withMessage) Unwrap() error { return w.error }
// nolint: errcheck
func (w *withMessage) Format(s fmt.State, verb rune) {
switch verb {
case 'v':
if s.Flag('+') {
fmt.Fprintf(s, "%+v\n", w.error)
io.WriteString(s, w.msg)
return
}
fallthrough
case 's', 'q':
io.WriteString(s, w.Error())
}
}