Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
cmd/cue: only ignore type and parse errors with get go
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
myitcv committed Mar 11, 2021
1 parent f014c14 commit cf5c48e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmd/cue/cmd/get_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,19 @@ func extract(cmd *Command, args []string) error {
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,
Expand Down
14 changes: 14 additions & 0 deletions cmd/cue/cmd/testdata/script/get_go_unresolvable_package.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cf5c48e

Please sign in to comment.