]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json: add "json: " prefix to SyntaxError messages
authorKevin Burke <kev@inburke.com>
Mon, 19 Oct 2020 20:29:40 +0000 (13:29 -0700)
committerKevin Burke <kev@inburke.com>
Wed, 21 Oct 2020 18:50:01 +0000 (18:50 +0000)
The other named errors - UnmarshalTypeError, etc - in this package do
the same, so we should prepend the package prefix to error messages
for consistency.

Add a note to the release docs in case this is interpreted as
a breaking change.

Fixes #36221.

Change-Id: Ie24b532bbf9812e108c259fa377e2a6b64319ed4
Reviewed-on: https://go-review.googlesource.com/c/go/+/263619
Run-TryBot: Kevin Burke <kev@inburke.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Kevin Burke <kev@inburke.com>
Trust: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
doc/go1.16.html
src/cmd/go/testdata/script/mod_proxy_invalid.txt
src/cmd/go/testdata/script/mod_query_empty.txt
src/encoding/json/scanner.go
src/html/template/escape_test.go

index 2f2e395729e49234ed84afb51101ce991ea2fc88..b6df0487ca96b8a0c9d51923b4b30a43c338773f 100644 (file)
@@ -216,6 +216,14 @@ Do not send CLs removing the interior tags from such phrases.
   of a malformed certificate.
 </p>
 
+<h3 id="encoding/json"><a href="/pkg/encoding/json">encoding/json</a></h3>
+
+<p><!-- CL 263619 -->
+  The error message for
+  <a href="/pkg/encoding/json/#SyntaxError">SyntaxError</a>
+  now begins with "json: ", matching the other errors in the package.
+</p>
+
 <h3 id="net"><a href="/pkg/net/">net</a></h3>
 
 <p><!-- CL 250357 -->
index 6427cc1527af3793236f9e42d4f5c31acc17514e..b9418b4df1215f1d210651e5ca1842c1396abce8 100644 (file)
@@ -2,7 +2,7 @@ env GO111MODULE=on
 env GOPROXY=$GOPROXY/invalid
 
 ! go list -m rsc.io/quote@latest
-stderr '^go list -m: module rsc.io/quote: invalid response from proxy "'$GOPROXY'": invalid character ''i'' looking for beginning of value$'
+stderr '^go list -m: module rsc.io/quote: invalid response from proxy "'$GOPROXY'": json: invalid character ''i'' looking for beginning of value$'
 
 ! go list -m rsc.io/quote@1.5.2
-stderr '^go list -m: rsc.io/quote@1.5.2: invalid version: invalid response from proxy "'$GOPROXY'": invalid character ''i'' looking for beginning of value$'
+stderr '^go list -m: rsc.io/quote@1.5.2: invalid version: invalid response from proxy "'$GOPROXY'": json: invalid character ''i'' looking for beginning of value$'
index b3ea3e3de0a5ac638012c0d51ef7fd01f166695d..a07a07c4bcc476a6dbcac9ba1b8d5ee03f311f43 100644 (file)
@@ -40,7 +40,7 @@ env GOPROXY=file:///$WORK/gatekeeper
 chmod 0000 $WORK/gatekeeper/example.com/join/subpkg/@latest
 cp go.mod.orig go.mod
 ! go get -d example.com/join/subpkg
-stderr 'go get example.com/join/subpkg: module example.com/join/subpkg: (invalid response from proxy ".+": invalid character .+|reading file://.*/gatekeeper/example.com/join/subpkg/@latest: .+)'
+stderr 'go get example.com/join/subpkg: module example.com/join/subpkg: (invalid response from proxy ".+": json: invalid character .+|reading file://.*/gatekeeper/example.com/join/subpkg/@latest: .+)'
 
 -- go.mod.orig --
 module example.com/othermodule
index 9dc1903e2db24b17d90ab90fb8de930131adb336..c3f5f6372db6376e90dd526e2ab5e092d36ae578 100644 (file)
@@ -47,7 +47,7 @@ type SyntaxError struct {
        Offset int64  // error occurred after reading Offset bytes
 }
 
-func (e *SyntaxError) Error() string { return e.msg }
+func (e *SyntaxError) Error() string { return "json: " + e.msg }
 
 // A scanner is a JSON scanning state machine.
 // Callers call scan.reset and then pass bytes in one at a time
index fbc84a75928b23077a2925598f472839c23b0fdd..b6031ea60ac07cb0f27b2f7be367ac2ffcc0f377 100644 (file)
@@ -243,7 +243,7 @@ func TestEscape(t *testing.T) {
                {
                        "badMarshaler",
                        `<button onclick='alert(1/{{.B}}in numbers)'>`,
-                       `<button onclick='alert(1/ /* json: error calling MarshalJSON for type *template.badMarshaler: invalid character &#39;f&#39; looking for beginning of object key string */null in numbers)'>`,
+                       `<button onclick='alert(1/ /* json: error calling MarshalJSON for type *template.badMarshaler: json: invalid character &#39;f&#39; looking for beginning of object key string */null in numbers)'>`,
                },
                {
                        "jsMarshaler",