diff --git a/src/cmd/go/internal/script/engine.go b/src/cmd/go/internal/script/engine.go index 88b10228c7..dfce755522 100644 --- a/src/cmd/go/internal/script/engine.go +++ b/src/cmd/go/internal/script/engine.go @@ -564,11 +564,14 @@ func (e *Engine) runCommand(s *State, cmd *command, impl Cmd) error { } wait, runErr := impl.Run(s, cmd.args...) - if runErr != nil { + if wait == nil { + if async && runErr == nil { + return cmdError(cmd, errors.New("internal error: async command returned a nil WaitFunc")) + } return checkStatus(cmd, runErr) } - if async && wait == nil { - return cmdError(cmd, errors.New("internal error: async command returned a nil WaitFunc")) + if runErr != nil { + return cmdError(cmd, errors.New("internal error: command returned both an error and a WaitFunc")) } if cmd.background { diff --git a/src/cmd/go/testdata/script/list_issue_56509.txt b/src/cmd/go/testdata/script/list_issue_56509.txt index d0ed9e4517..b402b2b397 100644 --- a/src/cmd/go/testdata/script/list_issue_56509.txt +++ b/src/cmd/go/testdata/script/list_issue_56509.txt @@ -4,9 +4,10 @@ # leading the package matching code to think there were Go files in the # directory.) +cd bar go list ./... ! stdout . - +cd .. [short] skip