-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
43 lines (36 loc) · 722 Bytes
/
error.go
File metadata and controls
43 lines (36 loc) · 722 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
41
42
43
package errorx
import (
"errors"
"fmt"
)
// New new error
func New(format string, args ...interface{}) error {
return fmt.Errorf("%s %s", getLocation(), fmt.Sprintf(format, args...))
}
// Trace trace
func Trace(err error) error {
if err == nil {
return nil
}
return fmt.Errorf("%s\n%w", getLocation(), err)
}
// Tracef trace
func Tracef(err error, format string, args ...interface{}) error {
if err == nil {
return nil
}
return fmt.Errorf("%s %s\n%w", getLocation(), fmt.Sprintf(format, args...), err)
}
// Cause return the root cause of the error
func Cause(err error) error {
if err == nil {
return nil
}
for {
next := errors.Unwrap(err)
if next == nil {
return err
}
err = next
}
}