Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go version -m exits with status 0 upon error #66426

Open
AGWA opened this issue Mar 20, 2024 · 3 comments · May be fixed by #66443
Open

cmd/go: go version -m exits with status 0 upon error #66426

AGWA opened this issue Mar 20, 2024 · 3 comments · May be fixed by #66443
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@AGWA
Copy link

AGWA commented Mar 20, 2024

Go version

go version go1.22.1 linux/amd64

Output of go env in your module/workspace:

N/A

What did you do?

Run go version -m on a non-Go executable, and then test the exit code of the go command. My use case is writing a script that detects whether a file is a Go executable or not, and only runs certain logic if so.

$ go version -m /bin/sh
$ echo $?

What did you see happen?

I saw a zero exit code, indicating success:

$ go version -m /bin/sh
/bin/sh: could not read Go build info from /bin/sh: not a Go executable
$ echo $?
0

What did you expect to see?

Since go version -m encountered an error, I expected to see a non-zero exit code, e.g.:

$ go version -m /bin/sh
/bin/sh: could not read Go build info from /bin/sh: not a Go executable
$ echo $?
1
@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 21, 2024
@dr2chase
Copy link
Contributor

@matloob @samthanawalla

qiulaidongfeng added a commit to qiulaidongfeng/go that referenced this issue Mar 21, 2024
Fixes golang#66426

Change-Id: Ie07ab6012063c0f087fd0525812079764444f8fa
@gopherbot
Copy link

Change https://go.dev/cl/573295 mentions this issue: cmd/go: fix version -m not go executable file exits with status 0

@matloob
Copy link
Contributor

matloob commented Mar 21, 2024

I think this error can be a little misleading. Not all Go binaries have embedded build info. We should probably return a non zero exit but for maybe we should reword the error to not mislead people.

qiulaidongfeng added a commit to qiulaidongfeng/go that referenced this issue Apr 14, 2024
Fixes golang#66426

Change-Id: Ie07ab6012063c0f087fd0525812079764444f8fa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants