From 6af088bfc66c13143c9ef46b4cf0805df77a8fbe Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Mon, 19 Oct 2020 13:29:40 -0700 Subject: [PATCH] encoding/json: add "json: " prefix to SyntaxError messages MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 TryBot-Result: Go Bot Trust: Kevin Burke Trust: Daniel Martí Reviewed-by: Daniel Martí --- doc/go1.16.html | 8 ++++++++ src/cmd/go/testdata/script/mod_proxy_invalid.txt | 4 ++-- src/cmd/go/testdata/script/mod_query_empty.txt | 2 +- src/encoding/json/scanner.go | 2 +- src/html/template/escape_test.go | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/doc/go1.16.html b/doc/go1.16.html index 2f2e395729..b6df0487ca 100644 --- a/doc/go1.16.html +++ b/doc/go1.16.html @@ -216,6 +216,14 @@ Do not send CLs removing the interior tags from such phrases. of a malformed certificate.

+

encoding/json

+ +

+ The error message for + SyntaxError + now begins with "json: ", matching the other errors in the package. +

+

net

diff --git a/src/cmd/go/testdata/script/mod_proxy_invalid.txt b/src/cmd/go/testdata/script/mod_proxy_invalid.txt index 6427cc1527..b9418b4df1 100644 --- a/src/cmd/go/testdata/script/mod_proxy_invalid.txt +++ b/src/cmd/go/testdata/script/mod_proxy_invalid.txt @@ -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$' diff --git a/src/cmd/go/testdata/script/mod_query_empty.txt b/src/cmd/go/testdata/script/mod_query_empty.txt index b3ea3e3de0..a07a07c4bc 100644 --- a/src/cmd/go/testdata/script/mod_query_empty.txt +++ b/src/cmd/go/testdata/script/mod_query_empty.txt @@ -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 diff --git a/src/encoding/json/scanner.go b/src/encoding/json/scanner.go index 9dc1903e2d..c3f5f6372d 100644 --- a/src/encoding/json/scanner.go +++ b/src/encoding/json/scanner.go @@ -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 diff --git a/src/html/template/escape_test.go b/src/html/template/escape_test.go index fbc84a7592..b6031ea60a 100644 --- a/src/html/template/escape_test.go +++ b/src/html/template/escape_test.go @@ -243,7 +243,7 @@ func TestEscape(t *testing.T) { { "badMarshaler", `