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

bz2 would use a dedicated exception for data error #85891

Open
mgorny mannequin opened this issue Sep 5, 2020 · 3 comments
Open

bz2 would use a dedicated exception for data error #85891

mgorny mannequin opened this issue Sep 5, 2020 · 3 comments
Labels
3.10 only security fixes extension-modules C modules in the Modules dir type-feature A feature request or enhancement

Comments

@mgorny
Copy link
Mannequin

mgorny mannequin commented Sep 5, 2020

BPO 41725
Nosy @terryjreedy, @mgorny, @serhiy-storchaka

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 = None
created_at = <Date 2020-09-05.10:26:14.525>
labels = ['extension-modules', 'type-feature', '3.10']
title = 'bz2 would use a dedicated exception for data error'
updated_at = <Date 2020-09-12.03:19:17.385>
user = 'https://github.com/mgorny'

bugs.python.org fields:

activity = <Date 2020-09-12.03:19:17.385>
actor = 'mgorny'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Extension Modules']
creation = <Date 2020-09-05.10:26:14.525>
creator = 'mgorny'
dependencies = []
files = []
hgrepos = []
issue_num = 41725
keywords = []
message_count = 3.0
messages = ['376427', '376744', '376769']
nosy_count = 3.0
nosy_names = ['terry.reedy', 'mgorny', 'serhiy.storchaka']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue41725'
versions = ['Python 3.10']

@mgorny
Copy link
Mannequin Author

mgorny mannequin commented Sep 5, 2020

Currently, the bz2 extension functions raise a generic OSError() on BZ_DATA_ERROR and BZ_DATA_ERROR_MAGIC. When working on files, this makes it unnecessarily hard to catch compressor errors (i.e. invalid bz2 input file) without catching system I/O errors. Could you please consider adding a new exception type for bz2 errors, akin to gzip.BadGzipFile?

@mgorny mgorny mannequin added extension-modules C modules in the Modules dir type-feature A feature request or enhancement labels Sep 5, 2020
@terryjreedy
Copy link
Member

An OSError for a file the OS can read seems a bit off. What is the accompanying message? Would something like ValueError("bz2 compressor failed with BZ_DATA_ERROR") be better?

Michał, are there precedents or models for this in the other file compression modules?

@terryjreedy terryjreedy added 3.10 only security fixes labels Sep 11, 2020
@mgorny
Copy link
Mannequin Author

mgorny mannequin commented Sep 12, 2020

An OSError for a file the OS can read seems a bit off. What is the accompanying message?

For example:

OSError: Invalid data stream

(I've just put random string into a file, and opened it as bzip2)

Would something like ValueError("bz2 compressor failed with BZ_DATA_ERROR") be better?

It would be a partial improvement. However, it would also break backwards compatibility with code already catching OSError. It might be better to go with custom exception type derived from OSError to keep existing code working.

Michał, are there precedents or models for this in the other file compression modules?

Python 3.8 has introduced BadGzipFile in gzip module, to replace their OSError.

lzma has used LZMAError from day one.

@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.10 only security fixes extension-modules C modules in the Modules dir type-feature A feature request or enhancement
Projects
Status: No status
Development

No branches or pull requests

1 participant