Skip to content

Commit 46ab7a5

Browse files
Lukas Joistengopherbot
Lukas Joisten
authored andcommitted
encoding/json: mention SyntaxError in Unmarshal doc comment
Change-Id: I71c9d9ef9d21a7ae9466d8c7b283fdfbba01f5a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/390734 Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Joseph Tsai <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 293d43e commit 46ab7a5

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/encoding/json/decode.go

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ import (
7575
// either be any string type, an integer, implement json.Unmarshaler, or
7676
// implement encoding.TextUnmarshaler.
7777
//
78+
// If the JSON-encoded data contain a syntax error, Unmarshal returns a SyntaxError.
79+
//
7880
// If a JSON value is not appropriate for a given target type,
7981
// or if a JSON number overflows the target type, Unmarshal
8082
// skips that field and completes the unmarshaling as best it can.

src/encoding/json/scanner.go

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func Valid(data []byte) bool {
2727

2828
// checkValid verifies that data is valid JSON-encoded data.
2929
// scan is passed in for use by checkValid to avoid an allocation.
30+
// checkValid returns nil or a SyntaxError.
3031
func checkValid(data []byte, scan *scanner) error {
3132
scan.reset()
3233
for _, c := range data {
@@ -42,6 +43,7 @@ func checkValid(data []byte, scan *scanner) error {
4243
}
4344

4445
// A SyntaxError is a description of a JSON syntax error.
46+
// Unmarshal will return a SyntaxError if the JSON can't be parsed.
4547
type SyntaxError struct {
4648
msg string // description of error
4749
Offset int64 // error occurred after reading Offset bytes

0 commit comments

Comments
 (0)