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.
This commit is contained in:
Mark Rushakoff 2018-11-09 16:31:45 -08:00
parent c92e73b702
commit bb1a80483a
2 changed files with 8 additions and 0 deletions

View File

@ -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 {

View File

@ -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/...$'