]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/api: fix no go files package panic
authorBaokun Lee <nototon@gmail.com>
Tue, 22 Jan 2019 16:22:53 +0000 (00:22 +0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 4 Mar 2019 15:32:18 +0000 (15:32 +0000)
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>
src/cmd/api/goapi.go
src/cmd/api/goapi_test.go
src/cmd/api/testdata/src/issue29837/p/README [new file with mode: 0644]

index 02dfa7c84128212dd38816cc6ff104bfcf4a2b4e..60359229dec7f39f0ec6195db988ada10b7c9f23 100644 (file)
@@ -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)
        }
index 1c8e2a345b6201699e5bfe6e4a3a20ea3dff6a58..fc1bcc908af2f43d32c7230e24bcf45c63bf658e 100644 (file)
@@ -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 (file)
index 0000000..770bc0f
--- /dev/null
@@ -0,0 +1 @@
+Empty directory for test, see https://golang.org/issues/29837.
\ No newline at end of file