From c8658027aaef94bb82b6dfcda70a3f4c4344a75b Mon Sep 17 00:00:00 2001 From: Aithal Date: Wed, 31 May 2017 09:11:48 -0700 Subject: [PATCH] pkg/types: modify LoadArgs to return a named error when an unmarshalable condition is detected --- pkg/types/args.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/types/args.go b/pkg/types/args.go index e87c6b6..bd8640f 100644 --- a/pkg/types/args.go +++ b/pkg/types/args.go @@ -63,6 +63,12 @@ func GetKeyField(keyString string, v reflect.Value) reflect.Value { return v.Elem().FieldByName(keyString) } +// UnmarshalableArgsError is used to indicate error unmarshalling args +// from the args-string in the form "K=V;K2=V2;..." +type UnmarshalableArgsError struct { + error +} + // LoadArgs parses args from a string in the form "K=V;K2=V2;..." func LoadArgs(args string, container interface{}) error { if args == "" { @@ -88,7 +94,9 @@ func LoadArgs(args string, container interface{}) error { keyFieldIface := keyField.Addr().Interface() u, ok := keyFieldIface.(encoding.TextUnmarshaler) if !ok { - return fmt.Errorf("ARGS: '%s' cannot be unmarshalled from textual form for pair %q", keyField, pair) + return UnmarshalableArgsError{fmt.Errorf( + "ARGS: cannot unmarshal into field '%s' - type '%s' does not implement encoding.TextUnmarshaler", + keyString, reflect.TypeOf(keyFieldIface))} } err := u.UnmarshalText([]byte(valueString)) if err != nil { -- 2.44.0