]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json/v2: fix typo in documentation about errors.AsType
authorJoe Tsai <joetsai@digital-static.net>
Fri, 24 Oct 2025 17:55:48 +0000 (10:55 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 24 Oct 2025 18:49:08 +0000 (11:49 -0700)
CL 708495 mass migrated the stdlib to use errors.AsType.
It rewrote the documentation, but uses the non-pointer type
of SemanticError or SyntacticError, which is invalid since
the Error method is declared on the pointer receiver.

Also, call errors.AsType on a separate line for readability.

Change-Id: I2eaf59614e2b58aa4bc8669ab81ce64168c54f13
Reviewed-on: https://go-review.googlesource.com/c/go/+/714660
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/encoding/json/jsontext/state.go
src/encoding/json/v2/errors.go
src/encoding/json/v2/example_test.go

index 538dfe32bfa9d2a812528b1c8cf04c6a45144b3f..e93057a34c577d22693495954fc0dede63c7d8ea 100644 (file)
@@ -24,7 +24,8 @@ import (
 // The name of a duplicate JSON object member can be extracted as:
 //
 //     err := ...
-//     if serr, ok := errors.AsType[jsontext.SyntacticError](err); ok && serr.Err == jsontext.ErrDuplicateName {
+//     serr, ok := errors.AsType[*jsontext.SyntacticError](err)
+//     if ok && serr.Err == jsontext.ErrDuplicateName {
 //             ptr := serr.JSONPointer // JSON pointer to duplicate name
 //             name := ptr.LastToken() // duplicate name itself
 //             ...
index 4421f8b821cb5cf95c3a0a10e09c828793f847f8..4895386fe2ca37e1071cbd1b89fd131cbdb90d84 100644 (file)
@@ -29,7 +29,8 @@ import (
 // The name of an unknown JSON object member can be extracted as:
 //
 //     err := ...
-//     if serr, ok := errors.AsType[json.SemanticError](err); ok && serr.Err == json.ErrUnknownName {
+//     serr, ok := errors.AsType[*json.SemanticError](err)
+//     if ok && serr.Err == json.ErrUnknownName {
 //             ptr := serr.JSONPointer // JSON pointer to unknown name
 //             name := ptr.LastToken() // unknown name itself
 //             ...
index 6d539bbd36b52934de1414fe78595d7d612a4ee8..dc1f06674ce24a0c2dd75da1b18bdb4eaf2b87d8 100644 (file)
@@ -371,7 +371,8 @@ 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))
-       if serr, ok := errors.AsType[*json.SemanticError](err); ok && serr.Err == json.ErrUnknownName {
+       serr, ok := errors.AsType[*json.SemanticError](err)
+       if ok && serr.Err == json.ErrUnknownName {
                fmt.Println("Unmarshal error:", serr.Err, strconv.Quote(serr.JSONPointer.LastToken()))
        }