cmd/cue: make get go operate on a best-efforts basis

Currently cue get go requires the source Go package to type check in
order to generate any output. This is generally not necessary or
appropriate, and indeed creates something of a chicken and egg problem
where the source package relies on the output of cue get go (for example
a go:embed directive is used to embed the CUE result of cue get go into
the package that was the source for cue get go, specifically see
golang.org/issue/44287).

Change-Id: I1e97e9433725ce5438e3ca2242c32dc7e87a081a
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8762
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/get_go.go b/cmd/cue/cmd/get_go.go
index 176ac2d..a261465 100644
--- a/cmd/cue/cmd/get_go.go
+++ b/cmd/cue/cmd/get_go.go
@@ -399,15 +399,6 @@
 	if err != nil {
 		return err
 	}
-	var errs []string
-	for _, P := range pkgs {
-		if len(P.Errors) > 0 {
-			errs = append(errs, fmt.Sprintf("\t%s: %v", P.PkgPath, P.Errors))
-		}
-	}
-	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_bad_embed.txt b/cmd/cue/cmd/testdata/script/get_go_bad_embed.txt
new file mode 100644
index 0000000..fc51dcb
--- /dev/null
+++ b/cmd/cue/cmd/testdata/script/get_go_bad_embed.txt
@@ -0,0 +1,38 @@
+# Test that we get a sensible error message when there is a type
+# checking error in the package that is being 'cue get go'-ed.
+
+[!go1.16] skip 'Only relevant for Go 1.16 and above'
+[golang.org/issue/44287] skip
+
+cue get go --local
+exec ls
+cmp cue.mod/gen/mod.com/blah/blah_go_gen.cue blah.cue.golden
+
+-- go.mod --
+module mod.com/blah
+
+go 1.14
+-- go.mod.golden --
+module mod.com/blah
+
+go 1.14
+-- blah.go --
+package main
+
+import _ "embed"
+
+// go:embed blah.txt
+var blah string
+
+type T struct {
+	Age int
+}
+
+-- blah.cue.golden --
+// Code generated by cue get go. DO NOT EDIT.
+
+//cue:generate cue get go mod.com/blah
+
+package main
+
+#T: Age: int
diff --git a/cmd/cue/cmd/testdata/script/get_go_type_errors.txt b/cmd/cue/cmd/testdata/script/get_go_type_errors.txt
new file mode 100644
index 0000000..b2cdac9
--- /dev/null
+++ b/cmd/cue/cmd/testdata/script/get_go_type_errors.txt
@@ -0,0 +1,38 @@
+# Test that we get expected results in the presence of type
+# check errors. In this mode, cue get go proceeds on a best-efforts
+# basis.
+
+cue get go --local
+cmp blah_go_gen.cue blah.cue.golden
+
+-- go.mod --
+module mod.com/blah
+
+go 1.14
+-- go.mod.golden --
+module mod.com/blah
+
+go 1.14
+-- blah.go --
+package main
+
+import _ "embed"
+
+// go:embed blah.txt
+var blah string
+
+// Syntax error
+type S
+
+type T struct {
+	Age int
+}
+
+-- blah.cue.golden --
+// Code generated by cue get go. DO NOT EDIT.
+
+//cue:generate cue get go mod.com/blah
+
+package main
+
+#T: Age: int