Skip to content
Permalink
Browse files

cmd/go: don't panic when go run is passed ... under nonexistent dir

Given a nonexistent directory above a wildcard:

    go run ./nonexistent/...

Print this error instead of panicking:

   go run: no packages loaded from ./nonexistent/...

Fixes golang#28696.
  • Loading branch information...
mark-rushakoff committed Nov 10, 2018
1 parent c92e73b commit bb1a80483ad26c8cf646cf0900d08cfe49aba535
Showing with 8 additions and 0 deletions.
  1. +3 −0 src/cmd/go/internal/run/run.go
  2. +5 −0 src/cmd/go/testdata/script/run_wildcard.txt
@@ -78,6 +78,9 @@ func runRun(cmd *base.Command, args []string) {
p = load.GoFilesPackage(files)
} else if len(args) > 0 && !strings.HasPrefix(args[0], "-") {
pkgs := load.PackagesAndErrors(args[:1])
if len(pkgs) == 0 {
base.Fatalf("go run: no packages loaded from %s", args[0])
}
if len(pkgs) > 1 {
var names []string
for _, p := range pkgs {
@@ -0,0 +1,5 @@
# Fix for https://github.com/golang/go/issues/28696:
# go run x/... should not panic when directory x doesn't exist.

! go run nonexistent/...
stderr '^go run: no packages loaded from nonexistent/...$'

0 comments on commit bb1a804

Please sign in to comment.
You can’t perform that action at this time.