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

python -m gzip handles error incorrectly #87482

Closed
rhpvorderman mannequin opened this issue Feb 24, 2021 · 9 comments
Closed

python -m gzip handles error incorrectly #87482

rhpvorderman mannequin opened this issue Feb 24, 2021 · 9 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@rhpvorderman
Copy link
Mannequin

rhpvorderman mannequin commented Feb 24, 2021

BPO 43316
Nosy @methane, @miss-islington, @rhpvorderman
PRs
  • bpo-43316: gzip: CLI uses non-zero return code on error. #24647
  • [3.9] bpo-43316: gzip: CLI uses non-zero return code on error. (GH-24647) #24648
  • [3.8] bpo-43316: gzip: CLI uses non-zero return code on error. (GH-24647) #24649
  • bpo-43316: gzip: Fix sys.exit() usage. #24652
  • [3.9] bpo-43316: gzip: Fix sys.exit() usage. (GH-24652) #24653
  • [3.8] bpo-43316: gzip: Fix sys.exit() usage. (GH-24652) #24654
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-02-26.02:37:07.748>
    created_at = <Date 2021-02-24.14:34:00.824>
    labels = ['type-bug', '3.8', '3.9', '3.10', '3.7', 'library']
    title = 'python -m gzip handles error incorrectly'
    updated_at = <Date 2021-02-26.02:37:07.747>
    user = 'https://github.com/rhpvorderman'

    bugs.python.org fields:

    activity = <Date 2021-02-26.02:37:07.747>
    actor = 'methane'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-02-26.02:37:07.748>
    closer = 'methane'
    components = ['Library (Lib)']
    creation = <Date 2021-02-24.14:34:00.824>
    creator = 'rhpvorderman'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43316
    keywords = ['patch']
    message_count = 9.0
    messages = ['387622', '387647', '387650', '387659', '387660', '387698', '387700', '387702', '387703']
    nosy_count = 3.0
    nosy_names = ['methane', 'miss-islington', 'rhpvorderman']
    pr_nums = ['24647', '24648', '24649', '24652', '24653', '24654']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43316'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10']

    @rhpvorderman
    Copy link
    Mannequin Author

    rhpvorderman mannequin commented Feb 24, 2021

    Python -m gzip -d myfile will throw an error because myfile does not end in '.gz'. That is fair (even though a bit redundant, GzipFile contains a header check, so why bother checking the extension?).

    The problem is how this error is thrown.

    1. Error is printed to stdout instead of stderr
    2. Tool exits with exit 0.

    This is not the behaviour that is expected when using python -m gzip in a script.

    The error is even codified in a test:

    def test_decompress_infile_outfile_error(self):

        def test_decompress_infile_outfile_error(self):
            rc, out, err = assert_python_ok('-m', 'gzip', '-d', 'thisisatest.out')
            self.assertIn(b"filename doesn't end in .gz:", out)
            self.assertEqual(rc, 0)
            self.assertEqual(err, b'')

    This should be assert_python_failure, out and err should be swapped, and exit code should be something different than 0.

    From the zen of python: Errors should never pass silently.

    I am willing to fix this in a PR, but first I would like some feedback on how to solve this exactly.

    I propose raising a ValueError("can not determine output filename: 'myfile' does not end in '.gz'").

    @rhpvorderman rhpvorderman mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 24, 2021
    @methane
    Copy link
    Member

    methane commented Feb 25, 2021

    I prefer sys.exit("message").

    @rhpvorderman
    Copy link
    Mannequin Author

    rhpvorderman mannequin commented Feb 25, 2021

    That sounds perfect, I didn't think of that. I will make a PR.

    @methane
    Copy link
    Member

    methane commented Feb 25, 2021

    New changeset cc3df63 by Ruben Vorderman in branch 'master':
    bpo-43316: gzip: CLI uses non-zero return code on error. (GH-24647)
    cc3df63

    @miss-islington
    Copy link
    Contributor

    New changeset 69906c5 by Miss Islington (bot) in branch '3.8':
    bpo-43316: gzip: CLI uses non-zero return code on error. (GH-24647)
    69906c5

    @methane
    Copy link
    Member

    methane commented Feb 26, 2021

    New changeset adea9b8 by Miss Islington (bot) in branch '3.9':
    bpo-43316: gzip: CLI uses non-zero return code on error. (GH-24647)
    adea9b8

    @methane
    Copy link
    Member

    methane commented Feb 26, 2021

    New changeset 9525a18 by Inada Naoki in branch 'master':
    bpo-43316: gzip: Fix sys.exit() usage. (GH-24652)
    9525a18

    @miss-islington
    Copy link
    Contributor

    New changeset 540749e by Miss Islington (bot) in branch '3.9':
    bpo-43316: gzip: Fix sys.exit() usage. (GH-24652)
    540749e

    @miss-islington
    Copy link
    Contributor

    New changeset 07ab490 by Miss Islington (bot) in branch '3.8':
    bpo-43316: gzip: Fix sys.exit() usage. (GH-24652)
    07ab490

    @methane methane closed this as completed Feb 26, 2021
    @methane methane closed this as completed Feb 26, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants