-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
44 lines (37 loc) · 777 Bytes
/
Copy patherror.go
File metadata and controls
44 lines (37 loc) · 777 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
44
package errors
import (
"errors"
"fmt"
"runtime"
)
//wrap an error to record stacktrace
func Wrap(err error) error {
if pc, file, line, ok := runtime.Caller(1); ok {
f := runtime.FuncForPC(pc)
var funcName string
if f != nil {
funcName = f.Name()
}
return fmt.Errorf("%w\n%s\n\t%s:%d", err, funcName, file, line)
}
return err
}
//return the original error without stacktrace
func Cause(err error) error {
for errors.Unwrap(err) != nil {
err = errors.Unwrap(err)
}
return err
}
func New(text string) error {
return errors.New(text)
}
func Unwrap(err error) error {
return errors.Unwrap(err)
}
func Is(err error, target error) bool {
return errors.Is(err, target)
}
func As(err error, target interface{}) bool {
return errors.As(err, target)
}