cmd/cue: only ignore type and parse errors with get go
Unknown or list-related errors should always be reported back to the
user. Otherwise, it's totally unclear what has gone wrong.
Change-Id: I9241acb100818dc051f852c98df0f94fb6e68c2b
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8961
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>
diff --git a/cmd/cue/cmd/get_go.go b/cmd/cue/cmd/get_go.go
index a261465..b76e967 100644
--- a/cmd/cue/cmd/get_go.go
+++ b/cmd/cue/cmd/get_go.go
@@ -399,6 +399,19 @@
if err != nil {
return err
}
+ var errs []string
+ for _, p := range pkgs {
+ for _, e := range p.Errors {
+ switch e.Kind {
+ case packages.ParseError, packages.TypeError:
+ default:
+ errs = append(errs, fmt.Sprintf("\t%s: %v", p.PkgPath, e))
+ }
+ }
+ }
+ if len(errs) > 0 {
+ return fmt.Errorf("could not load Go packages:\n%s", strings.Join(errs, "\n"))
+ }
e := extractor{
cmd: cmd,
diff --git a/cmd/cue/cmd/testdata/script/get_go_unresolvable_package.txt b/cmd/cue/cmd/testdata/script/get_go_unresolvable_package.txt
new file mode 100644
index 0000000..40bdecd
--- /dev/null
+++ b/cmd/cue/cmd/testdata/script/get_go_unresolvable_package.txt
@@ -0,0 +1,14 @@
+# Test that we get expected error when we ask cue get go to get
+# a Go package that cannot be resolved.
+
+# Ensure that we don't automatically add the missing dependency pre Go 1.16
+[!go1.16] env GOFLAGS=-mod=readonly
+
+! cue get go k8s.io/api/apps/v1
+[go1.16] stderr '\Qno required module provides package k8s.io/api/apps/v1'
+[go1.14] [!go1.16] stderr '\Qcannot find module providing package k8s.io/api/apps/v1: import lookup disabled by -mod=readonly'
+
+-- go.mod --
+module mod.com/blah
+
+go 1.14