-
Notifications
You must be signed in to change notification settings - Fork 0
/
error2.go
33 lines (25 loc) · 630 Bytes
/
error2.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
package error2
// TODO: add backtrace and chain report
import (
"errors"
"fmt"
"strings"
. "github.com/pkgs-go/fu"
)
func With(e error, f string, a ...interface{}) error {
f = strings.Replace(f, "{error?}", e.Error(), 1)
return &errorStr{fmt.Sprintf(f, a...), e, caller(1)}
}
func Errorf(f string, a ...interface{}) error {
return &errorStr{fmt.Sprintf(f, a...), nil, caller(1)}
}
func New(msg string, skip ...int) error {
s := Fnz(skip...)
return &errorStr{msg, nil, caller(s + 1)}
}
func (e *errorStr) Unwrap() error {
return e.error
}
func (e *errorStr) Is(err error) bool {
return errors.Is(e.error, err)
}