aboutsummaryrefslogtreecommitdiff
path: root/src/encoding
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding')
-rw-r--r--src/encoding/json/jsontext/coder_test.go2
-rw-r--r--src/encoding/json/jsontext/fuzz_test.go7
-rw-r--r--src/encoding/json/jsontext/state.go3
-rw-r--r--src/encoding/json/v2/errors.go3
-rw-r--r--src/encoding/json/v2/example_test.go3
5 files changed, 8 insertions, 10 deletions
diff --git a/src/encoding/json/jsontext/coder_test.go b/src/encoding/json/jsontext/coder_test.go
index 4a9efb3b8f..8602e3e7ff 100644
--- a/src/encoding/json/jsontext/coder_test.go
+++ b/src/encoding/json/jsontext/coder_test.go
@@ -486,7 +486,7 @@ func testCoderInterleaved(t *testing.T, where jsontest.CasePos, modeName string,
// Retry as a ReadToken call.
expectError := dec.PeekKind() == '}' || dec.PeekKind() == ']'
if expectError {
- if !errors.As(err, new(*SyntacticError)) {
+ if _, ok := errors.AsType[*SyntacticError](err); !ok {
t.Fatalf("%s: Decoder.ReadToken error is %T, want %T", where, err, new(SyntacticError))
}
tickTock = !tickTock
diff --git a/src/encoding/json/jsontext/fuzz_test.go b/src/encoding/json/jsontext/fuzz_test.go
index 60d16b9e27..3ad181d434 100644
--- a/src/encoding/json/jsontext/fuzz_test.go
+++ b/src/encoding/json/jsontext/fuzz_test.go
@@ -53,9 +53,10 @@ func FuzzCoder(f *testing.F) {
} else {
val, err := dec.ReadValue()
if err != nil {
- expectError := dec.PeekKind() == '}' || dec.PeekKind() == ']'
- if expectError && errors.As(err, new(*SyntacticError)) {
- continue
+ if expectError := dec.PeekKind() == '}' || dec.PeekKind() == ']'; expectError {
+ if _, ok := errors.AsType[*SyntacticError](err); ok {
+ continue
+ }
}
if err == io.EOF {
break
diff --git a/src/encoding/json/jsontext/state.go b/src/encoding/json/jsontext/state.go
index d214fd5190..538dfe32bf 100644
--- a/src/encoding/json/jsontext/state.go
+++ b/src/encoding/json/jsontext/state.go
@@ -24,8 +24,7 @@ import (
// The name of a duplicate JSON object member can be extracted as:
//
// err := ...
-// var serr jsontext.SyntacticError
-// if errors.As(err, &serr) && serr.Err == jsontext.ErrDuplicateName {
+// if serr, ok := errors.AsType[jsontext.SyntacticError](err); ok && serr.Err == jsontext.ErrDuplicateName {
// ptr := serr.JSONPointer // JSON pointer to duplicate name
// name := ptr.LastToken() // duplicate name itself
// ...
diff --git a/src/encoding/json/v2/errors.go b/src/encoding/json/v2/errors.go
index 9485d7b527..0f50d608c9 100644
--- a/src/encoding/json/v2/errors.go
+++ b/src/encoding/json/v2/errors.go
@@ -28,8 +28,7 @@ import (
// The name of an unknown JSON object member can be extracted as:
//
// err := ...
-// var serr json.SemanticError
-// if errors.As(err, &serr) && serr.Err == json.ErrUnknownName {
+// if serr, ok := errors.AsType[json.SemanticError](err); ok && serr.Err == json.ErrUnknownName {
// ptr := serr.JSONPointer // JSON pointer to unknown name
// name := ptr.LastToken() // unknown name itself
// ...
diff --git a/src/encoding/json/v2/example_test.go b/src/encoding/json/v2/example_test.go
index c6bf0a864d..6d539bbd36 100644
--- a/src/encoding/json/v2/example_test.go
+++ b/src/encoding/json/v2/example_test.go
@@ -371,8 +371,7 @@ func Example_unknownMembers() {
// Specifying RejectUnknownMembers causes Unmarshal
// to reject the presence of any unknown members.
err = json.Unmarshal([]byte(input), new(Color), json.RejectUnknownMembers(true))
- var serr *json.SemanticError
- if errors.As(err, &serr) && serr.Err == json.ErrUnknownName {
+ if serr, ok := errors.AsType[*json.SemanticError](err); ok && serr.Err == json.ErrUnknownName {
fmt.Println("Unmarshal error:", serr.Err, strconv.Quote(serr.JSONPointer.LastToken()))
}