aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/api
diff options
context:
space:
mode:
authorBaokun Lee <nototon@gmail.com>2019-01-23 00:22:53 +0800
committerBrad Fitzpatrick <bradfitz@golang.org>2019-03-04 15:32:18 +0000
commit68eb3ccdec3712b9da01b812a3baa1f1e7f07ff3 (patch)
tree24297b9a05f1c865e8babeeb8fac7959afe2f785 /src/cmd/api
parentd1887676d96daf969d886a4ec13cbad4908d51af (diff)
downloadgo-68eb3ccdec3712b9da01b812a3baa1f1e7f07ff3.tar.gz
go-68eb3ccdec3712b9da01b812a3baa1f1e7f07ff3.zip
cmd/api: fix no go files package panic
Fixes #29837 Change-Id: I7d57c24d2133932c076df6f41dd6589f777b65dd Reviewed-on: https://go-review.googlesource.com/c/158877 Run-TryBot: Baokun Lee <nototon@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/cmd/api')
-rw-r--r--src/cmd/api/goapi.go10
-rw-r--r--src/cmd/api/goapi_test.go13
-rw-r--r--src/cmd/api/testdata/src/issue29837/p/README1
3 files changed, 22 insertions, 2 deletions
diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go
index 02dfa7c841..60359229de 100644
--- a/src/cmd/api/goapi.go
+++ b/src/cmd/api/goapi.go
@@ -169,7 +169,13 @@ func main() {
// w.Import(name) will return nil
continue
}
- pkg, _ := w.Import(name)
+ pkg, err := w.Import(name)
+ if _, nogo := err.(*build.NoGoError); nogo {
+ continue
+ }
+ if err != nil {
+ log.Fatalf("Import(%q): %v", name, err)
+ }
w.export(pkg)
}
}
@@ -470,7 +476,7 @@ func (w *Walker) Import(name string) (*types.Package, error) {
info, err := context.ImportDir(dir, 0)
if err != nil {
if _, nogo := err.(*build.NoGoError); nogo {
- return nil, nil
+ return nil, err
}
log.Fatalf("pkg %q, dir %q: ScanDir: %v", name, dir, err)
}
diff --git a/src/cmd/api/goapi_test.go b/src/cmd/api/goapi_test.go
index 1c8e2a345b..fc1bcc908a 100644
--- a/src/cmd/api/goapi_test.go
+++ b/src/cmd/api/goapi_test.go
@@ -203,3 +203,16 @@ func TestIssue21181(t *testing.T) {
w.export(pkg)
}
}
+
+func TestIssue29837(t *testing.T) {
+ for _, c := range contexts {
+ c.Compiler = build.Default.Compiler
+ }
+ for _, context := range contexts {
+ w := NewWalker(context, "testdata/src/issue29837")
+ _, err := w.Import("p")
+ if _, nogo := err.(*build.NoGoError); !nogo {
+ t.Errorf("expected *build.NoGoError, got %T", err)
+ }
+ }
+}
diff --git a/src/cmd/api/testdata/src/issue29837/p/README b/src/cmd/api/testdata/src/issue29837/p/README
new file mode 100644
index 0000000000..770bc0f1b2
--- /dev/null
+++ b/src/cmd/api/testdata/src/issue29837/p/README
@@ -0,0 +1 @@
+Empty directory for test, see https://golang.org/issues/29837. \ No newline at end of file