aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMauri de Souza Meneguzzo <mauri870@gmail.com>2023-08-02 13:47:16 +0000
committerGopher Robot <gobot@golang.org>2023-08-02 15:53:43 +0000
commit07c72a0915093feb9837dbcbc963810a3efcb6b6 (patch)
treef181715ee5d7c2b2ed71f624bd5379c4d2778a21
parent041dd5ce051caf72d64b6d5f2f975515b3676a71 (diff)
downloadgo-07c72a0915093feb9837dbcbc963810a3efcb6b6.tar.xz
[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: 5d2889c60ceb3f43bb63b6641ecbcca08b7cd365 GitHub-Pull-Request: golang/go#61607 Reviewed-on: https://go-review.googlesource.com/c/go/+/513555 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-on: https://go-review.googlesource.com/c/go/+/515278 Auto-Submit: David Chase <drchase@google.com>
-rw-r--r--src/cmd/go/main.go6
-rw-r--r--src/cmd/go/testdata/script/go_badcmd.txt2
2 files changed, 7 insertions, 1 deletions
diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go
index 2898c68049..7b73642b5a 100644
--- a/src/cmd/go/main.go
+++ b/src/cmd/go/main.go
@@ -175,7 +175,11 @@ func main() {
if used > 0 {
helpArg += " " + strings.Join(args[:used], " ")
}
- fmt.Fprintf(os.Stderr, "go %s: unknown command\nRun 'go help%s' for usage.\n", cfg.CmdName, helpArg)
+ cmdName := cfg.CmdName
+ if cmdName == "" {
+ cmdName = args[0]
+ }
+ fmt.Fprintf(os.Stderr, "go %s: unknown command\nRun 'go help%s' for usage.\n", cmdName, helpArg)
base.SetExitStatus(2)
base.Exit()
}
diff --git a/src/cmd/go/testdata/script/go_badcmd.txt b/src/cmd/go/testdata/script/go_badcmd.txt
new file mode 100644
index 0000000000..661375adc6
--- /dev/null
+++ b/src/cmd/go/testdata/script/go_badcmd.txt
@@ -0,0 +1,2 @@
+! go asdf
+stderr '^go asdf: unknown command'