Commit 68eb3ccd authored by Baokun Lee's avatar Baokun Lee Committed by Brad Fitzpatrick

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent d1887676
...@@ -169,7 +169,13 @@ func main() { ...@@ -169,7 +169,13 @@ func main() {
// w.Import(name) will return nil // w.Import(name) will return nil
continue 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) w.export(pkg)
} }
} }
...@@ -470,7 +476,7 @@ func (w *Walker) Import(name string) (*types.Package, error) { ...@@ -470,7 +476,7 @@ func (w *Walker) Import(name string) (*types.Package, error) {
info, err := context.ImportDir(dir, 0) info, err := context.ImportDir(dir, 0)
if err != nil { if err != nil {
if _, nogo := err.(*build.NoGoError); nogo { if _, nogo := err.(*build.NoGoError); nogo {
return nil, nil return nil, err
} }
log.Fatalf("pkg %q, dir %q: ScanDir: %v", name, dir, err) log.Fatalf("pkg %q, dir %q: ScanDir: %v", name, dir, err)
} }
......
...@@ -203,3 +203,16 @@ func TestIssue21181(t *testing.T) { ...@@ -203,3 +203,16 @@ func TestIssue21181(t *testing.T) {
w.export(pkg) 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)
}
}
}
Empty directory for test, see https://golang.org/issues/29837.
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment