]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json: mention SyntaxError in Unmarshal doc comment
authorLukas Joisten <luckuck.f95@gmail.com>
Tue, 8 Mar 2022 11:21:00 +0000 (12:21 +0100)
committerGopher Robot <gobot@golang.org>
Wed, 1 Jun 2022 22:59:44 +0000 (22:59 +0000)
Change-Id: I71c9d9ef9d21a7ae9466d8c7b283fdfbba01f5a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/390734
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/encoding/json/decode.go
src/encoding/json/scanner.go

index 4319918d1e54215185db8f9f70b5e5c0c531ec18..01af489b563d53a6ae01d00aec949a87291147f6 100644 (file)
@@ -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.
index dbaa821becc10281ff456eae4cd406e82297d5f0..22fc6922da988b637437ac13700fcfea22b77045 100644 (file)
@@ -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