Skip to content

Commit c7f2f51

Browse files
author
Jay Conrod
committed
cmd/go: remove subcommand prefix from error messages
For example, errors that started before with "go mod download: " now start with "go: " instead. Previously, we had a mix of errors with and without subcommand prefixes, even in packages like modload that ostensibly aren't tied to any specific command. This change makes usage more consistent, which makes refactoring much easier. These prefixes didn't add useful information: the user should know the subcommand they just ran. But see CL 347152 for an attempt at making the opposite change: always printing the subcommand prefix. Note that there are a number of errors that don't start with "go: " or any subcommand prefix. This CL doesn't affect those. Change-Id: I16430d8c39ea3f4d0870f55a5205f06fb21943c0 Reviewed-on: https://go-review.googlesource.com/c/go/+/349597 Trust: Jay Conrod <[email protected]> Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 0bb40b0 commit c7f2f51

File tree

94 files changed

+353
-348
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+353
-348
lines changed

src/cmd/go/internal/base/tool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func Tool(toolName string) string {
3636
}
3737
// Give a nice message if there is no tool with that name.
3838
if _, err := os.Stat(toolPath); err != nil {
39-
fmt.Fprintf(os.Stderr, "go tool: no such tool %q\n", toolName)
39+
fmt.Fprintf(os.Stderr, "go: no such tool %q\n", toolName)
4040
SetExitStatus(2)
4141
Exit()
4242
}

src/cmd/go/internal/bug/bug.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func init() {
4040

4141
func runBug(ctx context.Context, cmd *base.Command, args []string) {
4242
if len(args) > 0 {
43-
base.Fatalf("go bug: bug takes no arguments")
43+
base.Fatalf("go: bug takes no arguments")
4444
}
4545
var buf bytes.Buffer
4646
buf.WriteString(bugHeader)

src/cmd/go/internal/clean/clean.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) {
144144
// This also mimics what os.RemoveAll(dir) would do.
145145
if err := os.RemoveAll(d); err != nil && !printedErrors {
146146
printedErrors = true
147-
base.Errorf("go clean -cache: %v", err)
147+
base.Errorf("go: %v", err)
148148
}
149149
}
150150
}
@@ -157,7 +157,7 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) {
157157
if !cfg.BuildN {
158158
if err := os.RemoveAll(logFile); err != nil && !printedErrors {
159159
printedErrors = true
160-
base.Errorf("go clean -cache: %v", err)
160+
base.Errorf("go: %v", err)
161161
}
162162
}
163163
}
@@ -187,22 +187,22 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) {
187187
}
188188
if err != nil {
189189
if _, statErr := os.Stat(dir); !os.IsNotExist(statErr) {
190-
base.Errorf("go clean -testcache: %v", err)
190+
base.Errorf("go: %v", err)
191191
}
192192
}
193193
}
194194
}
195195

196196
if cleanModcache {
197197
if cfg.GOMODCACHE == "" {
198-
base.Fatalf("go clean -modcache: no module cache")
198+
base.Fatalf("go: cannot clean -modcache without a module cache")
199199
}
200200
if cfg.BuildN || cfg.BuildX {
201201
b.Showcmd("", "rm -rf %s", cfg.GOMODCACHE)
202202
}
203203
if !cfg.BuildN {
204204
if err := modfetch.RemoveAll(cfg.GOMODCACHE); err != nil {
205-
base.Errorf("go clean -modcache: %v", err)
205+
base.Errorf("go: %v", err)
206206
}
207207
}
208208
}
@@ -245,7 +245,7 @@ func clean(p *load.Package) {
245245
}
246246
dirs, err := os.ReadDir(p.Dir)
247247
if err != nil {
248-
base.Errorf("go clean %s: %v", p.Dir, err)
248+
base.Errorf("go: %s: %v", p.Dir, err)
249249
return
250250
}
251251

@@ -334,7 +334,7 @@ func clean(p *load.Package) {
334334
}
335335
}
336336
if err := os.RemoveAll(filepath.Join(p.Dir, name)); err != nil {
337-
base.Errorf("go clean: %v", err)
337+
base.Errorf("go: %v", err)
338338
}
339339
}
340340
continue
@@ -386,5 +386,5 @@ func removeFile(f string) {
386386
return
387387
}
388388
}
389-
base.Errorf("go clean: %v", err)
389+
base.Errorf("go: %v", err)
390390
}

src/cmd/go/internal/envcmd/env.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,13 @@ func argKey(arg string) string {
193193

194194
func runEnv(ctx context.Context, cmd *base.Command, args []string) {
195195
if *envJson && *envU {
196-
base.Fatalf("go env: cannot use -json with -u")
196+
base.Fatalf("go: cannot use -json with -u")
197197
}
198198
if *envJson && *envW {
199-
base.Fatalf("go env: cannot use -json with -w")
199+
base.Fatalf("go: cannot use -json with -w")
200200
}
201201
if *envU && *envW {
202-
base.Fatalf("go env: cannot use -u with -w")
202+
base.Fatalf("go: cannot use -u with -w")
203203
}
204204

205205
// Handle 'go env -w' and 'go env -u' before calling buildcfg.Check,
@@ -277,7 +277,7 @@ func runEnv(ctx context.Context, cmd *base.Command, args []string) {
277277
func runEnvW(args []string) {
278278
// Process and sanity-check command line.
279279
if len(args) == 0 {
280-
base.Fatalf("go env -w: no KEY=VALUE arguments given")
280+
base.Fatalf("go: no KEY=VALUE arguments given")
281281
}
282282
osEnv := make(map[string]string)
283283
for _, e := range cfg.OrigEnv {
@@ -289,14 +289,14 @@ func runEnvW(args []string) {
289289
for _, arg := range args {
290290
i := strings.Index(arg, "=")
291291
if i < 0 {
292-
base.Fatalf("go env -w: arguments must be KEY=VALUE: invalid argument: %s", arg)
292+
base.Fatalf("go: arguments must be KEY=VALUE: invalid argument: %s", arg)
293293
}
294294
key, val := arg[:i], arg[i+1:]
295295
if err := checkEnvWrite(key, val); err != nil {
296-
base.Fatalf("go env -w: %v", err)
296+
base.Fatalf("go: %v", err)
297297
}
298298
if _, ok := add[key]; ok {
299-
base.Fatalf("go env -w: multiple values for key: %s", key)
299+
base.Fatalf("go: multiple values for key: %s", key)
300300
}
301301
add[key] = val
302302
if osVal := osEnv[key]; osVal != "" && osVal != val {
@@ -305,13 +305,13 @@ func runEnvW(args []string) {
305305
}
306306

307307
if err := checkBuildConfig(add, nil); err != nil {
308-
base.Fatalf("go env -w: %v", err)
308+
base.Fatalf("go: %v", err)
309309
}
310310

311311
gotmp, okGOTMP := add["GOTMPDIR"]
312312
if okGOTMP {
313313
if !filepath.IsAbs(gotmp) && gotmp != "" {
314-
base.Fatalf("go env -w: GOTMPDIR must be an absolute path")
314+
base.Fatalf("go: GOTMPDIR must be an absolute path")
315315
}
316316
}
317317

@@ -321,18 +321,18 @@ func runEnvW(args []string) {
321321
func runEnvU(args []string) {
322322
// Process and sanity-check command line.
323323
if len(args) == 0 {
324-
base.Fatalf("go env -u: no arguments given")
324+
base.Fatalf("go: 'go env -u' requires an argument")
325325
}
326326
del := make(map[string]bool)
327327
for _, arg := range args {
328328
if err := checkEnvWrite(arg, ""); err != nil {
329-
base.Fatalf("go env -u: %v", err)
329+
base.Fatalf("go: %v", err)
330330
}
331331
del[arg] = true
332332
}
333333

334334
if err := checkBuildConfig(nil, del); err != nil {
335-
base.Fatalf("go env -u: %v", err)
335+
base.Fatalf("go: %v", err)
336336
}
337337

338338
updateEnvFile(nil, del)
@@ -416,7 +416,7 @@ func printEnvAsJSON(env []cfg.EnvVar) {
416416
enc := json.NewEncoder(os.Stdout)
417417
enc.SetIndent("", "\t")
418418
if err := enc.Encode(m); err != nil {
419-
base.Fatalf("go env -json: %s", err)
419+
base.Fatalf("go: %s", err)
420420
}
421421
}
422422

@@ -494,11 +494,11 @@ func checkEnvWrite(key, val string) error {
494494
func updateEnvFile(add map[string]string, del map[string]bool) {
495495
file, err := cfg.EnvFile()
496496
if file == "" {
497-
base.Fatalf("go env: cannot find go env config: %v", err)
497+
base.Fatalf("go: cannot find go env config: %v", err)
498498
}
499499
data, err := os.ReadFile(file)
500500
if err != nil && (!os.IsNotExist(err) || len(add) == 0) {
501-
base.Fatalf("go env: reading go env config: %v", err)
501+
base.Fatalf("go: reading go env config: %v", err)
502502
}
503503

504504
lines := strings.SplitAfter(string(data), "\n")
@@ -556,7 +556,7 @@ func updateEnvFile(add map[string]string, del map[string]bool) {
556556
os.MkdirAll(filepath.Dir(file), 0777)
557557
err = os.WriteFile(file, data, 0666)
558558
if err != nil {
559-
base.Fatalf("go env: writing go env config: %v", err)
559+
base.Fatalf("go: writing go env config: %v", err)
560560
}
561561
}
562562
}

src/cmd/go/internal/get/get.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,16 @@ func init() {
114114
func runGet(ctx context.Context, cmd *base.Command, args []string) {
115115
if cfg.ModulesEnabled {
116116
// Should not happen: main.go should install the separate module-enabled get code.
117-
base.Fatalf("go get: modules not implemented")
117+
base.Fatalf("go: modules not implemented")
118118
}
119119

120120
work.BuildInit()
121121

122122
if *getF && !*getU {
123-
base.Fatalf("go get: cannot use -f flag without -u")
123+
base.Fatalf("go: cannot use -f flag without -u")
124124
}
125125
if *getInsecure {
126-
base.Fatalf("go get: -insecure flag is no longer supported; use GOINSECURE instead")
126+
base.Fatalf("go: -insecure flag is no longer supported; use GOINSECURE instead")
127127
}
128128

129129
// Disable any prompting for passwords by Git itself.
@@ -214,11 +214,11 @@ func downloadPaths(patterns []string) []string {
214214
// if the argument has no slash or refers to an existing file.
215215
if strings.HasSuffix(arg, ".go") {
216216
if !strings.Contains(arg, "/") {
217-
base.Errorf("go get %s: arguments must be package or module paths", arg)
217+
base.Errorf("go: %s: arguments must be package or module paths", arg)
218218
continue
219219
}
220220
if fi, err := os.Stat(arg); err == nil && !fi.IsDir() {
221-
base.Errorf("go get: %s exists as a file, but 'go get' requires package arguments", arg)
221+
base.Errorf("go: %s exists as a file, but 'go get' requires package arguments", arg)
222222
}
223223
}
224224
}

src/cmd/go/internal/list/list.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,12 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
427427
}
428428

429429
if modload.Init(); !modload.Enabled() {
430-
base.Fatalf("go list -m: not using modules")
430+
base.Fatalf("go: list -m cannot be used with GO111MODULE=off")
431431
}
432432

433433
modload.LoadModFile(ctx) // Sets cfg.BuildMod as a side-effect.
434434
if cfg.BuildMod == "vendor" {
435-
const actionDisabledFormat = "go list -m: can't %s using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)"
435+
const actionDisabledFormat = "go: can't %s using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)"
436436

437437
if *listVersions {
438438
base.Fatalf(actionDisabledFormat, "determine available versions")
@@ -471,11 +471,11 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
471471
if !*listE {
472472
for _, m := range mods {
473473
if m.Error != nil {
474-
base.Errorf("go list -m: %v", m.Error.Err)
474+
base.Errorf("go: %v", m.Error.Err)
475475
}
476476
}
477477
if err != nil {
478-
base.Errorf("go list -m: %v", err)
478+
base.Errorf("go: %v", err)
479479
}
480480
base.ExitIfErrors()
481481
}
@@ -711,7 +711,7 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
711711
}
712712
rmods, err := modload.ListModules(ctx, args, mode)
713713
if err != nil && !*listE {
714-
base.Errorf("go list -retracted: %v", err)
714+
base.Errorf("go: %v", err)
715715
}
716716
for i, arg := range args {
717717
rmod := rmods[i]

src/cmd/go/internal/modcmd/download.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) {
8787
// Check whether modules are enabled and whether we're in a module.
8888
modload.ForceUseModules = true
8989
if !modload.HasModRoot() && len(args) == 0 {
90-
base.Fatalf("go mod download: no modules specified (see 'go help mod download')")
90+
base.Fatalf("go: no modules specified (see 'go help mod download')")
9191
}
9292
haveExplicitArgs := len(args) > 0
9393
if !haveExplicitArgs {
@@ -106,7 +106,7 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) {
106106
for _, arg := range args {
107107
switch arg {
108108
case mainModule.Path, targetAtUpgrade, targetAtPatch:
109-
os.Stderr.WriteString("go mod download: skipping argument " + arg + " that resolves to the main module\n")
109+
os.Stderr.WriteString("go: skipping download of " + arg + " that resolves to the main module\n")
110110
}
111111
}
112112
}
@@ -192,7 +192,7 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) {
192192
for _, m := range mods {
193193
b, err := json.MarshalIndent(m, "", "\t")
194194
if err != nil {
195-
base.Fatalf("go mod download: %v", err)
195+
base.Fatalf("go: %v", err)
196196
}
197197
os.Stdout.Write(append(b, '\n'))
198198
if m.Error != "" {
@@ -202,7 +202,7 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) {
202202
} else {
203203
for _, m := range mods {
204204
if m.Error != "" {
205-
base.Errorf("go mod download: %v", m.Error)
205+
base.Errorf("go: %v", m.Error)
206206
}
207207
}
208208
base.ExitIfErrors()
@@ -222,6 +222,6 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) {
222222
// (after we've written the checksums for the modules that were downloaded
223223
// successfully).
224224
if infosErr != nil {
225-
base.Errorf("go mod download: %v", infosErr)
225+
base.Errorf("go: %v", infosErr)
226226
}
227227
}

0 commit comments

Comments
 (0)