Skip to content

Commit

Permalink
[release-branch.go1.11] cmd/go: don't panic when go run is passed ...…
Browse files Browse the repository at this point in the history
… 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/...

Updates #28696.
Fixes #28725

Change-Id: Iaa3bc5c78b14ef858d931778e1bc55ca626c5571
GitHub-Last-Rev: bb1a804
GitHub-Pull-Request: #28703
Reviewed-on: https://go-review.googlesource.com/c/148821
Run-TryBot: Emmanuel Odeke <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Bryan C. Mills <[email protected]>
Reviewed-by: Emmanuel Odeke <[email protected]>
(cherry picked from commit 529ea7c)
Reviewed-on: https://go-review.googlesource.com/c/149607
Run-TryBot: Ian Lance Taylor <[email protected]>
  • Loading branch information
mark-rushakoff authored and ianlancetaylor committed Nov 14, 2018
1 parent f3b9f36 commit e602388
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cmd/go/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions src/cmd/go/testdata/script/run_wildcard.txt
Original file line number Diff line number Diff line change
@@ -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 e602388

Please sign in to comment.