From bb1a80483ad26c8cf646cf0900d08cfe49aba535 Mon Sep 17 00:00:00 2001 From: Mark Rushakoff Date: Fri, 9 Nov 2018 16:31:45 -0800 Subject: [PATCH] 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 #28696. --- src/cmd/go/internal/run/run.go | 3 +++ src/cmd/go/testdata/script/run_wildcard.txt | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 src/cmd/go/testdata/script/run_wildcard.txt diff --git a/src/cmd/go/internal/run/run.go b/src/cmd/go/internal/run/run.go index 303e6842e7be3..feccf23b2782a 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 0000000000000..cd401e00e6441 --- /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/...$'