[New-bugs-announce] [issue43316] python -m gzip handles error incorrectly
report at bugs.python.org
Wed Feb 24 09:34:00 EST 2021
New submission from Ruben Vorderman <r.h.p.vorderman at lumc.nl>:
`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: https://github.com/python/cpython/blob/1f433406bd46fbd00b88223ad64daea6bc9eaadc/Lib/test/test_gzip.py#L776
rc, out, err = assert_python_ok('-m', 'gzip', '-d', 'thisisatest.out')
self.assertIn(b"filename doesn't end in .gz:", out)
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'").
components: Library (Lib)
title: python -m gzip handles error incorrectly
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce