-
Notifications
You must be signed in to change notification settings - Fork 18k
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
os/exec: add example of handling exec.Error and exec.ExitError #35874
Comments
FYI, |
@ianlancetaylor why can't |
if err == exec.ExitError { so you can't write if errors.Is(err, exec.ExitError) { Yes, you have to call |
I use |
If you choose to write code with no tests then I suggest that you at least add |
Change https://golang.org/cl/213337 mentions this issue: |
https://golang.org/pkg/os/exec provides
exec.Error
andexec.ExitError
error types and doesn't document how to check and distinguish between them.What version of Go are you using (
go version
)?What did you do?
I am using https://golang.org/pkg/os/exec/#Cmd.Output to capture the output of
dnf
command and check its return code. The doc saysAny returned error will usually be of type *ExitError
. However, trying to detect error witherrors.Is(err, exec.ExitError)
(as mentioned in https://golang.org/pkg/errors/) fails with./prog.go:20:15: type exec.ExitError is not an expression
.https://play.golang.org/p/7hjN2PCyBgB
What did you expect to see?
Expect to separate error when command not found (seems to be
*exec.Error
) and when command run successfully with return code (*exec.ExitError
). Expect to read exit code fromdnf
somehow which is part of its API.Expect to see the example of distinguishing between these two errors and reading the exit code in Output example.
What did you see instead?
The text was updated successfully, but these errors were encountered: