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

display.PrintErr swallows error and app retuns with exit code 0 #1321

Open
jchappelow opened this issue Jan 29, 2025 · 0 comments
Open

display.PrintErr swallows error and app retuns with exit code 0 #1321

jchappelow opened this issue Jan 29, 2025 · 0 comments
Assignees

Comments

@jchappelow
Copy link
Member

jchappelow commented Jan 29, 2025

Most cases a command or application error should result in a non zero exit code to the shell. This does not happen when display.PrintErr is used since it swallows the error that is given back to cobra, resulting in a zero (success) exit code. This is both confusing and bad for scripting.

Another pitfall of display.PrintErr returning a nil error when given a (non-nil) error is that if misused in subfunctions rather than directly in the actually cobra RunE, it will often be used to direct logic (assuming there was no error but there was). I recently fixed several such misuses, so it would be good to somehow consider this in resolving the issue of cmd exit code.

@jchappelow jchappelow self-assigned this Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant