Skip to content

Commit 747fe2e

Browse files
dsnetgopherbot
authored andcommitted
encoding/json/v2: fix typo in documentation about errors.AsType
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 <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Johan Brandhorst-Satzkorn <[email protected]> Auto-Submit: Joseph Tsai <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 94f47fc commit 747fe2e

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/encoding/json/jsontext/state.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import (
2424
// The name of a duplicate JSON object member can be extracted as:
2525
//
2626
// err := ...
27-
// if serr, ok := errors.AsType[jsontext.SyntacticError](err); ok && serr.Err == jsontext.ErrDuplicateName {
27+
// serr, ok := errors.AsType[*jsontext.SyntacticError](err)
28+
// if ok && serr.Err == jsontext.ErrDuplicateName {
2829
// ptr := serr.JSONPointer // JSON pointer to duplicate name
2930
// name := ptr.LastToken() // duplicate name itself
3031
// ...

src/encoding/json/v2/errors.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import (
2929
// The name of an unknown JSON object member can be extracted as:
3030
//
3131
// err := ...
32-
// if serr, ok := errors.AsType[json.SemanticError](err); ok && serr.Err == json.ErrUnknownName {
32+
// serr, ok := errors.AsType[*json.SemanticError](err)
33+
// if ok && serr.Err == json.ErrUnknownName {
3334
// ptr := serr.JSONPointer // JSON pointer to unknown name
3435
// name := ptr.LastToken() // unknown name itself
3536
// ...

src/encoding/json/v2/example_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ func Example_unknownMembers() {
371371
// Specifying RejectUnknownMembers causes Unmarshal
372372
// to reject the presence of any unknown members.
373373
err = json.Unmarshal([]byte(input), new(Color), json.RejectUnknownMembers(true))
374-
if serr, ok := errors.AsType[*json.SemanticError](err); ok && serr.Err == json.ErrUnknownName {
374+
serr, ok := errors.AsType[*json.SemanticError](err)
375+
if ok && serr.Err == json.ErrUnknownName {
375376
fmt.Println("Unmarshal error:", serr.Err, strconv.Quote(serr.JSONPointer.LastToken()))
376377
}
377378

0 commit comments

Comments
 (0)