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.

Change-Id: Iaa3bc5c78b14ef858d931778e1bc55ca626c5571
GitHub-Last-Rev: bb1a804
GitHub-Pull-Request: golang#28703
Reviewed-on: https://go-review.googlesource.com/c/148821
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
  • Loading branch information...
mark-rushakoff authored and odeke-em committed Nov 14, 2018
1 parent c92e73b commit 529ea7c0de1f9e582280c73031ae870f868e7908
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 529ea7c

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