cue: fix Issue 289

Classical nil-interface bug

Closes #289

Change-Id: Id42a4eb07e147183a83883f35e169a8dea8a0311
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5003
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/testdata/script/issue289.txt b/cmd/cue/cmd/testdata/script/issue289.txt
new file mode 100644
index 0000000..12588aa
--- /dev/null
+++ b/cmd/cue/cmd/testdata/script/issue289.txt
@@ -0,0 +1,13 @@
+! cue import test.yaml -p kube -l 'strings.ToCamel(kind)' -l metadata.name -f
+cmp stderr expect-stderr
+
+-- test.yaml --
+apiVersion: v1
+kind: Service
+metadata:
+  name: ingress-nginx
+spec:
+  type: NodePort
+---
+-- expect-stderr --
+unsupported label path type: instance is not a struct, found null
diff --git a/cue/errors.go b/cue/errors.go
index b9e988f..a8af56d 100644
--- a/cue/errors.go
+++ b/cue/errors.go
@@ -232,8 +232,10 @@
 }
 
 func (idx *index) mkErr(src source, args ...interface{}) *bottom {
-	e := &bottom{baseValue: src.base(), index: idx, pos: src}
-
+	e := &bottom{index: idx, pos: src}
+	if src != nil {
+		e.baseValue = src.base()
+	}
 	if v, ok := src.(value); ok {
 		e.value = v
 	}
diff --git a/cue/instance.go b/cue/instance.go
index d2f9c8c..aea89a9 100644
--- a/cue/instance.go
+++ b/cue/instance.go
@@ -154,7 +154,8 @@
 	}
 	obj, ok := root.(*structLit)
 	if !ok {
-		return ctx.mkErr(obj, "instance is not a struct")
+		return ctx.mkErr(root, "instance is not a struct, found %s",
+			root.kind())
 	}
 	v := newVisitor(ctx.index, inst.inst, nil, obj, true)
 	return v.walk(expr).evalPartial(ctx)