@@ -90,8 +90,9 @@ type Unmarshaler interface {
90
90
// An UnmarshalTypeError describes a JSON value that was
91
91
// not appropriate for a value of a specific Go type.
92
92
type UnmarshalTypeError struct {
93
- Value string // description of JSON value - "bool", "array", "number -5"
94
- Type reflect.Type // type of Go value it could not be assigned to
93
+ Value string // description of JSON value - "bool", "array", "number -5"
94
+ Type reflect.Type // type of Go value it could not be assigned to
95
+ Offset int64 // error occurred after reading Offset bytes
95
96
}
96
97
97
98
func (e * UnmarshalTypeError ) Error () string {
@@ -377,7 +378,7 @@ func (d *decodeState) array(v reflect.Value) {
377
378
return
378
379
}
379
380
if ut != nil {
380
- d .saveError (& UnmarshalTypeError {"array" , v .Type ()})
381
+ d .saveError (& UnmarshalTypeError {"array" , v .Type (), int64 ( d . off ) })
381
382
d .off --
382
383
d .next ()
383
384
return
@@ -396,7 +397,7 @@ func (d *decodeState) array(v reflect.Value) {
396
397
// Otherwise it's invalid.
397
398
fallthrough
398
399
default :
399
- d .saveError (& UnmarshalTypeError {"array" , v .Type ()})
400
+ d .saveError (& UnmarshalTypeError {"array" , v .Type (), int64 ( d . off ) })
400
401
d .off --
401
402
d .next ()
402
403
return
@@ -485,7 +486,7 @@ func (d *decodeState) object(v reflect.Value) {
485
486
return
486
487
}
487
488
if ut != nil {
488
- d .saveError (& UnmarshalTypeError {"object" , v .Type ()})
489
+ d .saveError (& UnmarshalTypeError {"object" , v .Type (), int64 ( d . off ) })
489
490
d .off --
490
491
d .next () // skip over { } in input
491
492
return
@@ -504,7 +505,7 @@ func (d *decodeState) object(v reflect.Value) {
504
505
// map must have string kind
505
506
t := v .Type ()
506
507
if t .Key ().Kind () != reflect .String {
507
- d .saveError (& UnmarshalTypeError {"object" , v .Type ()})
508
+ d .saveError (& UnmarshalTypeError {"object" , v .Type (), int64 ( d . off ) })
508
509
d .off --
509
510
d .next () // skip over { } in input
510
511
return
@@ -515,7 +516,7 @@ func (d *decodeState) object(v reflect.Value) {
515
516
case reflect .Struct :
516
517
517
518
default :
518
- d .saveError (& UnmarshalTypeError {"object" , v .Type ()})
519
+ d .saveError (& UnmarshalTypeError {"object" , v .Type (), int64 ( d . off ) })
519
520
d .off --
520
521
d .next () // skip over { } in input
521
522
return
@@ -646,7 +647,7 @@ func (d *decodeState) convertNumber(s string) (interface{}, error) {
646
647
}
647
648
f , err := strconv .ParseFloat (s , 64 )
648
649
if err != nil {
649
- return nil , & UnmarshalTypeError {"number " + s , reflect .TypeOf (0.0 )}
650
+ return nil , & UnmarshalTypeError {"number " + s , reflect .TypeOf (0.0 ), int64 ( d . off ) }
650
651
}
651
652
return f , nil
652
653
}
@@ -679,7 +680,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool
679
680
if fromQuoted {
680
681
d .saveError (fmt .Errorf ("json: invalid use of ,string struct tag, trying to unmarshal %q into %v" , item , v .Type ()))
681
682
} else {
682
- d .saveError (& UnmarshalTypeError {"string" , v .Type ()})
683
+ d .saveError (& UnmarshalTypeError {"string" , v .Type (), int64 ( d . off ) })
683
684
}
684
685
}
685
686
s , ok := unquoteBytes (item )
@@ -713,15 +714,15 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool
713
714
if fromQuoted {
714
715
d .saveError (fmt .Errorf ("json: invalid use of ,string struct tag, trying to unmarshal %q into %v" , item , v .Type ()))
715
716
} else {
716
- d .saveError (& UnmarshalTypeError {"bool" , v .Type ()})
717
+ d .saveError (& UnmarshalTypeError {"bool" , v .Type (), int64 ( d . off ) })
717
718
}
718
719
case reflect .Bool :
719
720
v .SetBool (value )
720
721
case reflect .Interface :
721
722
if v .NumMethod () == 0 {
722
723
v .Set (reflect .ValueOf (value ))
723
724
} else {
724
- d .saveError (& UnmarshalTypeError {"bool" , v .Type ()})
725
+ d .saveError (& UnmarshalTypeError {"bool" , v .Type (), int64 ( d . off ) })
725
726
}
726
727
}
727
728
@@ -736,10 +737,10 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool
736
737
}
737
738
switch v .Kind () {
738
739
default :
739
- d .saveError (& UnmarshalTypeError {"string" , v .Type ()})
740
+ d .saveError (& UnmarshalTypeError {"string" , v .Type (), int64 ( d . off ) })
740
741
case reflect .Slice :
741
742
if v .Type () != byteSliceType {
742
- d .saveError (& UnmarshalTypeError {"string" , v .Type ()})
743
+ d .saveError (& UnmarshalTypeError {"string" , v .Type (), int64 ( d . off ) })
743
744
break
744
745
}
745
746
b := make ([]byte , base64 .StdEncoding .DecodedLen (len (s )))
@@ -755,7 +756,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool
755
756
if v .NumMethod () == 0 {
756
757
v .Set (reflect .ValueOf (string (s )))
757
758
} else {
758
- d .saveError (& UnmarshalTypeError {"string" , v .Type ()})
759
+ d .saveError (& UnmarshalTypeError {"string" , v .Type (), int64 ( d . off ) })
759
760
}
760
761
}
761
762
@@ -777,7 +778,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool
777
778
if fromQuoted {
778
779
d .error (fmt .Errorf ("json: invalid use of ,string struct tag, trying to unmarshal %q into %v" , item , v .Type ()))
779
780
} else {
780
- d .error (& UnmarshalTypeError {"number" , v .Type ()})
781
+ d .error (& UnmarshalTypeError {"number" , v .Type (), int64 ( d . off ) })
781
782
}
782
783
case reflect .Interface :
783
784
n , err := d .convertNumber (s )
@@ -786,31 +787,31 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool
786
787
break
787
788
}
788
789
if v .NumMethod () != 0 {
789
- d .saveError (& UnmarshalTypeError {"number" , v .Type ()})
790
+ d .saveError (& UnmarshalTypeError {"number" , v .Type (), int64 ( d . off ) })
790
791
break
791
792
}
792
793
v .Set (reflect .ValueOf (n ))
793
794
794
795
case reflect .Int , reflect .Int8 , reflect .Int16 , reflect .Int32 , reflect .Int64 :
795
796
n , err := strconv .ParseInt (s , 10 , 64 )
796
797
if err != nil || v .OverflowInt (n ) {
797
- d .saveError (& UnmarshalTypeError {"number " + s , v .Type ()})
798
+ d .saveError (& UnmarshalTypeError {"number " + s , v .Type (), int64 ( d . off ) })
798
799
break
799
800
}
800
801
v .SetInt (n )
801
802
802
803
case reflect .Uint , reflect .Uint8 , reflect .Uint16 , reflect .Uint32 , reflect .Uint64 , reflect .Uintptr :
803
804
n , err := strconv .ParseUint (s , 10 , 64 )
804
805
if err != nil || v .OverflowUint (n ) {
805
- d .saveError (& UnmarshalTypeError {"number " + s , v .Type ()})
806
+ d .saveError (& UnmarshalTypeError {"number " + s , v .Type (), int64 ( d . off ) })
806
807
break
807
808
}
808
809
v .SetUint (n )
809
810
810
811
case reflect .Float32 , reflect .Float64 :
811
812
n , err := strconv .ParseFloat (s , v .Type ().Bits ())
812
813
if err != nil || v .OverflowFloat (n ) {
813
- d .saveError (& UnmarshalTypeError {"number " + s , v .Type ()})
814
+ d .saveError (& UnmarshalTypeError {"number " + s , v .Type (), int64 ( d . off ) })
814
815
break
815
816
}
816
817
v .SetFloat (n )
0 commit comments