From: Lukas Joisten Date: Tue, 8 Mar 2022 11:21:00 +0000 (+0100) Subject: encoding/json: mention SyntaxError in Unmarshal doc comment X-Git-Tag: go1.19beta1~90 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=46ab7a5c4f80d912f25b6b3e1044282a2a79df8b;p=gostls13.git 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 Reviewed-by: Dmitri Shuralyov Reviewed-by: Joseph Tsai Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor TryBot-Result: Gopher Robot --- diff --git a/src/encoding/json/decode.go b/src/encoding/json/decode.go index 4319918d1e..01af489b56 100644 --- a/src/encoding/json/decode.go +++ b/src/encoding/json/decode.go @@ -75,6 +75,8 @@ import ( // either be any string type, an integer, implement json.Unmarshaler, or // implement encoding.TextUnmarshaler. // +// If the JSON-encoded data contain a syntax error, Unmarshal returns a SyntaxError. +// // If a JSON value is not appropriate for a given target type, // or if a JSON number overflows the target type, Unmarshal // skips that field and completes the unmarshaling as best it can. diff --git a/src/encoding/json/scanner.go b/src/encoding/json/scanner.go index dbaa821bec..22fc6922da 100644 --- a/src/encoding/json/scanner.go +++ b/src/encoding/json/scanner.go @@ -27,6 +27,7 @@ func Valid(data []byte) bool { // checkValid verifies that data is valid JSON-encoded data. // scan is passed in for use by checkValid to avoid an allocation. +// checkValid returns nil or a SyntaxError. func checkValid(data []byte, scan *scanner) error { scan.reset() for _, c := range data { @@ -42,6 +43,7 @@ func checkValid(data []byte, scan *scanner) error { } // A SyntaxError is a description of a JSON syntax error. +// Unmarshal will return a SyntaxError if the JSON can't be parsed. type SyntaxError struct { msg string // description of error Offset int64 // error occurred after reading Offset bytes