-
Notifications
You must be signed in to change notification settings - Fork 19
/
error.go
56 lines (44 loc) · 831 Bytes
/
error.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
52
53
54
55
56
package errors
import (
"fmt"
"github.com/pkg/errors"
)
type Coder interface {
Code() string
}
func New(message string) error {
return errors.New(message)
}
func Errorf(format string, args ...interface{}) error {
return errors.Errorf(format, args...)
}
func Cause(err error) error {
return errors.Cause(err)
}
func Trace(err error) error {
if err == nil {
return nil
}
switch err.(type) {
case fmt.Formatter:
return err
default:
return errors.WithStack(err)
}
}
func CodeError(code, message string) error {
return &codeError{errors.New(message), code}
}
type codeError struct {
e error
c string
}
func (e *codeError) Code() string {
return e.c
}
func (e *codeError) Error() string {
return e.e.Error()
}
func (e *codeError) Format(s fmt.State, verb rune) {
e.e.(fmt.Formatter).Format(s, verb)
}