aboutsummaryrefslogtreecommitdiff
path: root/src/encoding
diff options
context:
space:
mode:
authorEmil Hessman <emil@hessman.se>2014-12-27 20:52:17 +0100
committerMikio Hara <mikioh.mikioh@gmail.com>2014-12-28 10:43:37 +0000
commit2c987e16937a6abf907ab230b04d42c071a388f5 (patch)
treec4ac9c30e438e28bf521f2a0695b3ca2d735b9dc /src/encoding
parentb6e913806ec85f18614ab825fce4e99aae94f899 (diff)
downloadgo-2c987e16937a6abf907ab230b04d42c071a388f5.tar.xz
encoding/json: address go vet reports
The error message for decoding a unquoted value into a struct field with the ,string option specified has two arguments when one is needed. Make the error message take one argument and add a test in order to cover the case when a unquoted value is specified. Also add error value as the missing argument for Fatalf call in test. Fixes the following go vet reports: decode.go:602: wrong number of args for format in Errorf call: 1 needed but 2 args decode_test.go:1088: missing argument for Fatalf("%v"): format reads arg 1, have only 0 args Change-Id: Id036e10c54c4a7c1ee9952f6910858ecc2b84134 Reviewed-on: https://go-review.googlesource.com/2109 Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Diffstat (limited to 'src/encoding')
-rw-r--r--src/encoding/json/decode.go2
-rw-r--r--src/encoding/json/decode_test.go3
2 files changed, 3 insertions, 2 deletions
diff --git a/src/encoding/json/decode.go b/src/encoding/json/decode.go
index 705bc2e17a..212365cede 100644
--- a/src/encoding/json/decode.go
+++ b/src/encoding/json/decode.go
@@ -599,7 +599,7 @@ func (d *decodeState) object(v reflect.Value) {
case string:
d.literalStore([]byte(qv), subv, true)
default:
- d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal unquoted value into %v", item, v.Type()))
+ d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal unquoted value into %v", subv.Type()))
}
} else {
d.value(subv)
diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go
index 7235969b9f..83b9d39ad6 100644
--- a/src/encoding/json/decode_test.go
+++ b/src/encoding/json/decode_test.go
@@ -688,6 +688,7 @@ var wrongStringTests = []wrongStringTest{
{`{"result":"x"}`, `json: invalid use of ,string struct tag, trying to unmarshal "x" into string`},
{`{"result":"foo"}`, `json: invalid use of ,string struct tag, trying to unmarshal "foo" into string`},
{`{"result":"123"}`, `json: invalid use of ,string struct tag, trying to unmarshal "123" into string`},
+ {`{"result":123}`, `json: invalid use of ,string struct tag, trying to unmarshal unquoted value into string`},
}
// If people misuse the ,string modifier, the error message should be
@@ -1085,7 +1086,7 @@ func TestNullString(t *testing.T) {
*s.C = 2
err := Unmarshal(data, &s)
if err != nil {
- t.Fatalf("Unmarshal: %v")
+ t.Fatalf("Unmarshal: %v", err)
}
if s.B != 1 || s.C != nil {
t.Fatalf("after Unmarshal, s.B=%d, s.C=%p, want 1, nil", s.B, s.C)