From 4a17e2a1f9a9435db21101dc687bd9aa75f03d98 Mon Sep 17 00:00:00 2001 From: Krishna Kumar S <71367204+Krishks369@users.noreply.github.com> Date: Sat, 4 Mar 2023 09:02:21 +0530 Subject: [PATCH] Add errorcontext to unmarshalString() --- unmarshaler.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/unmarshaler.go b/unmarshaler.go index 5c19845e..8f2a8f1b 100644 --- a/unmarshaler.go +++ b/unmarshaler.go @@ -979,12 +979,18 @@ func (d *decoder) unmarshalString(value *unstable.Node, v reflect.Value) error { case reflect.Interface: v.Set(reflect.ValueOf(string(value.Data))) default: + ctx := d.errorContext + if ctx != nil && ctx.Struct != nil { + f := ctx.Struct.FieldByIndex(ctx.Field) + return unstable.NewParserErrorWithContext(d.p.Raw(value.Raw), "cannot store TOML string into struct field %s.%s of type %s", f.Name, f.Type, v.Kind()) + } return unstable.NewParserError(d.p.Raw(value.Raw), "cannot store TOML string into a Go %s", v.Kind()) } return nil } + func (d *decoder) handleKeyValue(expr *unstable.Node, v reflect.Value) (reflect.Value, error) { d.strict.EnterKeyValue(expr)