From efc5237265a91d70ad7dd25565a7d949b5afb922 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 12 Nov 2023 15:24:16 -0500 Subject: [PATCH] lang: types: Improve error handling of value code We can give a bit more feedback and try and also catch a rare scenario. --- lang/types/value.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lang/types/value.go b/lang/types/value.go index 1edd23e9..54a72f36 100644 --- a/lang/types/value.go +++ b/lang/types/value.go @@ -233,7 +233,7 @@ func ValueOf(v reflect.Value) (Value, error) { }, nil default: - return nil, fmt.Errorf("unable to represent value of %+v", v) + return nil, fmt.Errorf("unable to represent value of %+v which has kind: %v", v, kind) } } @@ -280,6 +280,10 @@ func Into(v Value, rv reflect.Value) error { return fmt.Errorf("cannot Into() %+v of type %s into %s", v, v.Type(), typ) } + if typ == nil { + return fmt.Errorf("cannot Into() %+v of type %s into a nil type", v, v.Type()) + } + switch v := v.(type) { case *BoolValue: if err := mustInto(reflect.Bool); err != nil {