[issue41725] bz2 would use a dedicated exception for data error

2020-09-11 Thread Michał Górny
Michał Górny added the comment: > 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

[issue41725] bz2 would use a dedicated exception for data error

2020-09-11 Thread Terry J. Reedy
Terry J. Reedy added the comment: 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

[issue41725] bz2 would use a dedicated exception for data error

2020-09-05 Thread Michał Górny
New submission from Michał Górny : 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.