-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.go
51 lines (41 loc) · 1.52 KB
/
new.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
46
47
48
49
50
51
package errors
import (
"errors"
"fmt"
)
// New creates a new error
func New(msg string) error {
return NewError(getCallerPath(0), errors.New(msg), nil)
}
// Newf creates a new formatted error
func Newf(format string, params ...any) error {
return NewError(getCallerPath(0), errors.New(fmt.Sprintf(format, params...)), nil)
}
// Wrap wraps the error
func Wrap(inner error) error {
return NewError(getCallerPath(0), nil, inner)
}
// Warpe creates a new error with inner error
func Wrape(err error, inner error) error {
return NewError(getCallerPath(0), err, inner)
}
// Wrapf creates a new formatted error with inner error
func Wrapf(inner error, format string, params ...any) error {
return NewError(getCallerPath(0), errors.New(fmt.Sprintf(format, params...)), inner)
}
// NewSkip creates a new error with custom stack skip
func NewSkip(skip int, msg string) error {
return NewError(getCallerPath(skip), errors.New(msg), nil)
}
// NewSkipf creates a new formatted error with custom stack skip
func NewSkipf(skip int, format string, params ...any) error {
return NewError(getCallerPath(skip), errors.New(fmt.Sprintf(format, params...)), nil)
}
// WrapSkip wraps the error with custom stack skip
func WrapSkip(skip int, inner error) error {
return NewError(getCallerPath(skip), nil, inner)
}
// WrapSkipf creates a new formatted error with inner error and custom stack skip
func WrapSkipf(skip int, inner error, format string, params ...any) error {
return NewError(getCallerPath(skip), errors.New(fmt.Sprintf(format, params...)), inner)
}