Skip to content

Commit 07c72a0

Browse files
mauri870gopherbot
authored andcommitted
[release-branch.go1.21] cmd/go: missing name in failed command error
Fixed the error reporting for an unknown command to preserve the name when displaying the error message. Fixes #61604 Change-Id: I13defb84e61265ab48ab514e9d4f1626a4a3f758 GitHub-Last-Rev: 5d2889c GitHub-Pull-Request: #61607 Reviewed-on: https://go-review.googlesource.com/c/go/+/513555 Run-TryBot: Russ Cox <[email protected]> Reviewed-by: David Chase <[email protected]> Auto-Submit: Russ Cox <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Russ Cox <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/go/+/515278 Auto-Submit: David Chase <[email protected]>
1 parent 041dd5c commit 07c72a0

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/cmd/go/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ func main() {
175175
if used > 0 {
176176
helpArg += " " + strings.Join(args[:used], " ")
177177
}
178-
fmt.Fprintf(os.Stderr, "go %s: unknown command\nRun 'go help%s' for usage.\n", cfg.CmdName, helpArg)
178+
cmdName := cfg.CmdName
179+
if cmdName == "" {
180+
cmdName = args[0]
181+
}
182+
fmt.Fprintf(os.Stderr, "go %s: unknown command\nRun 'go help%s' for usage.\n", cmdName, helpArg)
179183
base.SetExitStatus(2)
180184
base.Exit()
181185
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
! go asdf
2+
stderr '^go asdf: unknown command'

0 commit comments

Comments
 (0)