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: unexpected exit codes for go tool ... #17145

Closed
yaojingguo opened this issue Sep 18, 2016 · 6 comments
Closed

cmd/go: unexpected exit codes for go tool ... #17145

yaojingguo opened this issue Sep 18, 2016 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@yaojingguo
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.7.1 linux/amd64

https://golang.org/cmd/vet/ says:

Vet's exit code is 2 for erroneous invocation of the tool, 1 if a problem was reported, and 0 otherwise.

The vet exit code is set by setExit function. A check of the source code in src/cmd/vet shows that there is no invocation like setExit(2). Should the doc be updated to reflect the code logic?

@robpike
Copy link
Contributor

robpike commented Sep 18, 2016

It's correct as is. It exits with code 2 if the arguments are incorrect, that is, if Usage is called.

@robpike robpike closed this as completed Sep 18, 2016
@yaojingguo
Copy link
Contributor Author

go vet behaves as the documentation describes. But go tool vet does not.

$ go tool vet -h
$ echo $?
1

@robpike robpike reopened this Sep 18, 2016
@robpike robpike changed the title doc: incorrect description of exit code for vet cmd/go: unexpected exit codes for go tool ... Sep 18, 2016
@robpike
Copy link
Contributor

robpike commented Sep 18, 2016

The go tool subcommand mishandles error codes. It's not disastrous but the codes are odd.

% go tool asdf
go tool: no such tool "asdf"
% echo $?
3
% 

That one is due to an explicit setExitCode(3); it should be 2.

% go vet -asdf
<errors>
% echo $?
2
% go tool vet -asdf
<same errors>
% echo $?
1
% 

One would expect the go tool vet command to exit with the same code as go vet. Also, as one expects, the vet binary run without the go tool exits with 2 in this case.

@robpike robpike self-assigned this Sep 18, 2016
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 3, 2016
@quentinmit quentinmit added this to the Go1.8 milestone Oct 3, 2016
@robpike
Copy link
Contributor

robpike commented Oct 16, 2016

This error, the second one above,

% go vet -asdf
<errors>
% echo $?
2
% go tool vet -asdf
<same errors>
% echo $?
1
% 

is not cleanly addressable because os.ProcessState does not tell you the failing exit code portably; in fact, the exit code is simply unix-specific. Might as well leave it alone; at least it's non-zero indicating command failure.

@gopherbot
Copy link

CL https://golang.org/cl/31253 mentions this issue.

@yaojingguo
Copy link
Contributor Author

If we leave it alone, I think that the related description in https://golang.org/cmd/vet/ should be updated.

@golang golang locked and limited conversation to collaborators Oct 17, 2017
@rsc rsc unassigned robpike Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants