diff options
author | Jay Conrod <jayconrod@google.com> | 2021-03-04 10:35:17 -0500 |
---|---|---|
committer | Jay Conrod <jayconrod@google.com> | 2021-03-04 22:41:34 +0000 |
commit | b87e9b9f68f1eb0d685fd250b3b47495710e0059 (patch) | |
tree | 38eff73215ed1f8124c7d53c95e1e32897d212d0 /src/cmd/go/internal/run/run.go | |
parent | a99ff24a26939f30440dd0f06dce426ed5e638ee (diff) | |
download | go-b87e9b9f68f1eb0d685fd250b3b47495710e0059.tar.gz go-b87e9b9f68f1eb0d685fd250b3b47495710e0059.zip |
cmd/go: clarify errors for commands run outside a module
The new error message tells the user what was wrong (no go.mod found)
and directs them to 'go help modules', which links to tutorials.
Fixes #44745
Change-Id: I98f31fec4a8757eb1792b45491519da4c552cb0f
Reviewed-on: https://go-review.googlesource.com/c/go/+/298650
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/run/run.go')
-rw-r--r-- | src/cmd/go/internal/run/run.go | 20 |
1 files changed, 2 insertions, 18 deletions
diff --git a/src/cmd/go/internal/run/run.go b/src/cmd/go/internal/run/run.go index 99578b244c..666b1a0e56 100644 --- a/src/cmd/go/internal/run/run.go +++ b/src/cmd/go/internal/run/run.go @@ -96,28 +96,12 @@ func runRun(ctx context.Context, cmd *base.Command, args []string) { base.Fatalf("go run: no go files listed") } cmdArgs := args[i:] - if p.Error != nil { - base.Fatalf("%s", p.Error) - } + load.CheckPackageErrors([]*load.Package{p}) - p.Internal.OmitDebug = true - if len(p.DepsErrors) > 0 { - // Since these are errors in dependencies, - // the same error might show up multiple times, - // once in each package that depends on it. - // Only print each once. - printed := map[*load.PackageError]bool{} - for _, err := range p.DepsErrors { - if !printed[err] { - printed[err] = true - base.Errorf("%s", err) - } - } - } - base.ExitIfErrors() if p.Name != "main" { base.Fatalf("go run: cannot run non-main package") } + p.Internal.OmitDebug = true p.Target = "" // must build - not up to date if p.Internal.CmdlineFiles { //set executable name if go file is given as cmd-argument |