Decoding error position tracking
This commit is contained in:
+16
-1
@@ -268,11 +268,22 @@ func (d *decoder) unmarshalValue(x target, node ast.Node) error {
|
||||
return unmarshalLocalDateTime(x, node)
|
||||
case ast.DateTime:
|
||||
return unmarshalDateTime(x, node)
|
||||
case ast.LocalDate:
|
||||
return unmarshalLocalDate(x, node)
|
||||
default:
|
||||
panic(fmt.Errorf("unhandled unmarshalValue kind %s", node.Kind))
|
||||
}
|
||||
}
|
||||
|
||||
func unmarshalLocalDate(x target, node ast.Node) error {
|
||||
assertNode(ast.LocalDate, node)
|
||||
v, err := parseLocalDate(node.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return setDate(x, v)
|
||||
}
|
||||
|
||||
func unmarshalLocalDateTime(x target, node ast.Node) error {
|
||||
assertNode(ast.LocalDateTime, node)
|
||||
v, rest, err := parseLocalDateTime(node.Data)
|
||||
@@ -280,7 +291,7 @@ func unmarshalLocalDateTime(x target, node ast.Node) error {
|
||||
return err
|
||||
}
|
||||
if len(rest) > 0 {
|
||||
return fmt.Errorf("extra characters at the end of a local date time")
|
||||
return newDecodeError(rest, "extra characters at the end of a local date time")
|
||||
}
|
||||
return setLocalDateTime(x, v)
|
||||
}
|
||||
@@ -302,6 +313,10 @@ func setDateTime(x target, v time.Time) error {
|
||||
return x.set(reflect.ValueOf(v))
|
||||
}
|
||||
|
||||
func setDate(x target, v LocalDate) error {
|
||||
return x.set(reflect.ValueOf(v))
|
||||
}
|
||||
|
||||
func unmarshalString(x target, node ast.Node) error {
|
||||
assertNode(ast.String, node)
|
||||
return setString(x, string(node.Data))
|
||||
|
||||
Reference in New Issue
Block a user