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

bpo-43316: gzip: CLI uses non-zero return code on error. #24647

Merged
merged 2 commits into from Feb 25, 2021

Conversation

rhpvorderman
Copy link
Contributor

@rhpvorderman rhpvorderman commented Feb 25, 2021

Exit code is now 1 instead of 0. A message is printed to stderr instead of stdout. This is
the proper behaviour for a tool that can be used in scripts.

In my opinion this change should be backported to all currently supported versions of python. Exiting with 0 upon error is not acceptable behaviour for a tool. Luckily, I think the backport will be quite easy and I am happy to do it.

https://bugs.python.org/issue43316

Exit code is now 1 instead of 0. A message is printed to stderr instead of stdout. This is
the proper behaviour for a tool that can be used in scripts.
@methane methane added needs backport to 3.8 only security fixes needs backport to 3.9 only security fixes type-bug An unexpected behavior, bug, or error labels Feb 25, 2021
@methane methane changed the title bpo-43316: @rhpvorderman Handle failure due to extension properly in gzip CLI bpo-43316: gzip: CLI returns 1 and print error message to stderr. Feb 25, 2021
@methane methane changed the title bpo-43316: gzip: CLI returns 1 and print error message to stderr. bpo-43316: gzip: CLI returns 1 on error. Feb 25, 2021
@methane methane changed the title bpo-43316: gzip: CLI returns 1 on error. bpo-43316: gzip: CLI uses non-zero return code on error. Feb 25, 2021
@methane methane merged commit cc3df63 into python:master Feb 25, 2021
@miss-islington
Copy link
Contributor

Thanks @rhpvorderman for the PR, and @methane for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8, 3.9.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 25, 2021
)

Exit code is now 1 instead of 0. A message is printed to stderr instead of stdout. This is
the proper behaviour for a tool that can be used in scripts.
(cherry picked from commit cc3df63)

Co-authored-by: Ruben Vorderman <r.h.p.vorderman@lumc.nl>
@bedevere-bot
Copy link

GH-24648 is a backport of this pull request to the 3.9 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Feb 25, 2021
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 25, 2021
)

Exit code is now 1 instead of 0. A message is printed to stderr instead of stdout. This is
the proper behaviour for a tool that can be used in scripts.
(cherry picked from commit cc3df63)

Co-authored-by: Ruben Vorderman <r.h.p.vorderman@lumc.nl>
@bedevere-bot bedevere-bot removed the needs backport to 3.8 only security fixes label Feb 25, 2021
@bedevere-bot
Copy link

GH-24649 is a backport of this pull request to the 3.8 branch.

miss-islington added a commit that referenced this pull request Feb 25, 2021
Exit code is now 1 instead of 0. A message is printed to stderr instead of stdout. This is
the proper behaviour for a tool that can be used in scripts.
(cherry picked from commit cc3df63)

Co-authored-by: Ruben Vorderman <r.h.p.vorderman@lumc.nl>
@rhpvorderman
Copy link
Contributor Author

Thanks @methane !

@@ -583,8 +583,7 @@ def main():
g = sys.stdout.buffer
else:
if arg[-3:] != ".gz":
print("filename doesn't end in .gz:", repr(arg))
continue
sys.exit("filename doesn't end in .gz:", repr(arg))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t this use string concatenation or f-string to pass one argument to sys.exit?

Signature is sys.exit(status=None)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! We can not pass two strings to sys.exit().
I don't know why this passed the test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I got it. The stderr is:

Traceback (most recent call last):
(snip)
  File "/Users/inada-n/work/python/cpython/Lib/gzip.py", line 586, in main
    sys.exit("filename doesn't end in .gz:", repr(arg))
TypeError: exit expected at most 1 argument, got 2

And it passes the test self.assertIn(b"filename doesn't end in .gz:", err).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #24652

methane pushed a commit that referenced this pull request Feb 26, 2021
Exit code is now 1 instead of 0. A message is printed to stderr instead of stdout. This is
the proper behaviour for a tool that can be used in scripts.
(cherry picked from commit cc3df63)

Co-authored-by: Ruben Vorderman <r.h.p.vorderman@lumc.nl>
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
)

Exit code is now 1 instead of 0. A message is printed to stderr instead of stdout. This is
the proper behaviour for a tool that can be used in scripts.
kreathon pushed a commit to kreathon/cpython that referenced this pull request May 2, 2021
)

Exit code is now 1 instead of 0. A message is printed to stderr instead of stdout. This is
the proper behaviour for a tool that can be used in scripts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants