-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspalling.go
More file actions
40 lines (31 loc) · 765 Bytes
/
Copy pathspalling.go
File metadata and controls
40 lines (31 loc) · 765 Bytes
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
package spalling // import "github.com/jbowes/spalling"
import (
"fmt"
"golang.org/x/xerrors"
)
func Wrap(err error, msg string, skip uint) *Wrapper {
return &Wrapper{*Seal(err, msg, skip+1)}
}
func Seal(err error, msg string, skip uint) *Sealer {
return &Sealer{
msg: msg,
err: err,
frame: xerrors.Caller(int(2 + skip)),
}
}
type Sealer struct {
msg string
err error
frame xerrors.Frame
}
func (e *Sealer) Error() string { return fmt.Sprint(e) }
func (e *Sealer) Format(s fmt.State, v rune) { xerrors.FormatError(e, s, v) }
func (e *Sealer) FormatError(p xerrors.Printer) (next error) {
p.Print(e.msg)
e.frame.Format(p)
return e.err
}
type Wrapper struct {
Sealer
}
func (e *Wrapper) Unwrap() error { return e.err }