Skip to content

Commit e602388

Browse files
mark-rushakoffianlancetaylor
authored andcommitted
[release-branch.go1.11] 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/... 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 <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> (cherry picked from commit 529ea7c) Reviewed-on: https://go-review.googlesource.com/c/149607 Run-TryBot: Ian Lance Taylor <iant@golang.org>
1 parent f3b9f36 commit e602388

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/cmd/go/internal/run/run.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ func runRun(cmd *base.Command, args []string) {
7878
p = load.GoFilesPackage(files)
7979
} else if len(args) > 0 && !strings.HasPrefix(args[0], "-") {
8080
pkgs := load.PackagesAndErrors(args[:1])
81+
if len(pkgs) == 0 {
82+
base.Fatalf("go run: no packages loaded from %s", args[0])
83+
}
8184
if len(pkgs) > 1 {
8285
var names []string
8386
for _, p := range pkgs {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Fix for https://github.com/golang/go/issues/28696:
2+
# go run x/... should not panic when directory x doesn't exist.
3+
4+
! go run nonexistent/...
5+
stderr '^go run: no packages loaded from nonexistent/...$'

0 commit comments

Comments
 (0)