@@ -6,9 +6,8 @@ package jsonrpc2
6
6
7
7
import (
8
8
"encoding/json"
9
+ "errors"
9
10
"fmt"
10
-
11
- "golang.org/x/xerrors"
12
11
)
13
12
14
13
// Code represents a error's category.
@@ -66,62 +65,41 @@ type Error struct {
66
65
// information about the error. Can be omitted.
67
66
Data * json.RawMessage `json:"data"`
68
67
69
- frame xerrors.Frame
70
- err error
68
+ err error
71
69
}
72
70
73
- // Error implements error.
71
+ // compile time check whether the Error implements error interface.
72
+ var _ error = (* Error )(nil )
73
+
74
+ // Error implements error.Error.
74
75
func (e * Error ) Error () string {
75
76
if e == nil {
76
77
return ""
77
78
}
78
79
return e .Message
79
80
}
80
81
81
- // Format implements fmt.Formatter.
82
- func (e * Error ) Format (s fmt.State , c rune ) {
83
- xerrors .FormatError (e , s , c )
84
- }
85
-
86
- // FormatError implements xerrors.Formatter.
87
- func (e * Error ) FormatError (p xerrors.Printer ) (next error ) {
88
- if e .Message == "" {
89
- p .Printf ("code=%v" , e .Code )
90
- } else {
91
- p .Printf ("%s (code=%v)" , e .Message , e .Code )
92
- }
93
- e .frame .Format (p )
94
-
95
- return e .err
96
- }
97
-
98
- // Unwrap implements xerrors.Wrapper.
82
+ // Unwrap implements errors.Unwrap.
99
83
//
100
- // The returns the error underlying the receiver, which may be nil.
101
- func (e * Error ) Unwrap () error {
102
- return e .err
103
- }
84
+ // Returns the error underlying the receiver, which may be nil.
85
+ func (e * Error ) Unwrap () error { return e .err }
104
86
105
87
// NewError builds a Error struct for the suppied message and code.
106
- func NewError (c Code , args ... interface {} ) * Error {
107
- e := & Error {
88
+ func NewError (c Code , message string ) * Error {
89
+ return & Error {
108
90
Code : c ,
109
- Message : fmt . Sprint ( args ... ) ,
110
- frame : xerrors . Caller ( 1 ),
91
+ Message : message ,
92
+ err : errors . New ( message ),
111
93
}
112
- e .err = xerrors .New (e .Message )
113
-
114
- return e
115
94
}
116
95
117
96
// Errorf builds a Error struct for the suppied message and code.
118
97
func Errorf (c Code , format string , args ... interface {}) * Error {
119
98
e := & Error {
120
- Code : c ,
121
- Message : fmt .Sprintf (format , args ... ),
122
- frame : xerrors .Caller (1 ),
99
+ Code : c ,
100
+ err : fmt .Errorf (format , args ... ),
123
101
}
124
- e .err = xerrors . New ( e . Message )
102
+ e .Message = e . err . Error ( )
125
103
126
104
return e
127
105
}
0 commit comments