Skip to content

Commit bb1a804

Browse files
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 golang#28696.
1 parent c92e73b commit bb1a804

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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

+3
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 {
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)