aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Rushakoff <mark.rushakoff@gmail.com>2018-11-14 19:34:48 +0000
committerIan Lance Taylor <iant@golang.org>2018-11-14 23:53:17 +0000
commite602388f98e174895e9adb5f2516b38dc692d45d (patch)
treede8254e45a6dc5db4a63382043801f045971cded
parentf3b9f362c9f81fba61663002eac7f065afd9afd1 (diff)
downloadgo-e602388f98e174895e9adb5f2516b38dc692d45d.tar.gz
go-e602388f98e174895e9adb5f2516b38dc692d45d.zip
[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: bb1a80483ad26c8cf646cf0900d08cfe49aba535 GitHub-Pull-Request: golang/go#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 529ea7c0de1f9e582280c73031ae870f868e7908) Reviewed-on: https://go-review.googlesource.com/c/149607 Run-TryBot: Ian Lance Taylor <iant@golang.org>
-rw-r--r--src/cmd/go/internal/run/run.go3
-rw-r--r--src/cmd/go/testdata/script/run_wildcard.txt5
2 files changed, 8 insertions, 0 deletions
diff --git a/src/cmd/go/internal/run/run.go b/src/cmd/go/internal/run/run.go
index 303e6842e7..feccf23b27 100644
--- a/src/cmd/go/internal/run/run.go
+++ b/src/cmd/go/internal/run/run.go
@@ -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 {
diff --git a/src/cmd/go/testdata/script/run_wildcard.txt b/src/cmd/go/testdata/script/run_wildcard.txt
new file mode 100644
index 0000000000..cd401e00e6
--- /dev/null
+++ b/src/cmd/go/testdata/script/run_wildcard.txt
@@ -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/...$'