File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,12 @@ type SyntaxError struct {
49
49
50
50
func (e * SyntaxError ) Error () string { return e .msg }
51
51
52
+ // Is returns true if target is a SyntaxError.
53
+ func (e * SyntaxError ) Is (target error ) bool {
54
+ _ , ok := target .(* SyntaxError )
55
+ return ok
56
+ }
57
+
52
58
// A scanner is a JSON scanning state machine.
53
59
// Callers call scan.reset and then pass bytes in one at a time
54
60
// by calling scan.step(&scan, c) for each byte.
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ package json
6
6
7
7
import (
8
8
"bytes"
9
+ "errors"
10
+ "fmt"
9
11
"math"
10
12
"math/rand"
11
13
"reflect"
@@ -201,6 +203,13 @@ func TestIndentErrors(t *testing.T) {
201
203
}
202
204
}
203
205
206
+ func TestSyntaxErrorIs (t * testing.T ) {
207
+ err := fmt .Errorf ("apackage: %w: failed to parse struct" , & SyntaxError {"some error" , 43 })
208
+ if ! errors .Is (err , & SyntaxError {}) {
209
+ t .Fatalf ("%v should be unwrapped to a SyntaxError" , err )
210
+ }
211
+ }
212
+
204
213
func diff (t * testing.T , a , b []byte ) {
205
214
for i := 0 ; ; i ++ {
206
215
if i >= len (a ) || i >= len (b ) || a [i ] != b [i ] {
You can’t perform that action at this time.
0 commit comments