haskell/zlib

no non-internal way to catch exception from decompress?

Closed this issue · 16 comments

I was surprised to discover (via a production crash) that Zlib.decompress throws its own exception, not an IOError. Also, it looks like the only place its exception is exported is Codec.Compression.Zlib.Internal, which implies I shouldn't be using it normally.

How about re-exporting the exception from Zlib and GZip, and then augmenting the documentation to say exactly what exception will be thrown? As a bonus it would be nice to have an example, because I initially thought ByteString.Lazy.toStrict should be enough, but you also need an Exception.evaluate in there.

I can make a pull request if you want.

+1, would also like a Maybe ByteString or Either ZLibException ByteString version of the API.

The new incremental API is stable enough that we should promote it from the internal module.

hvr commented

@dcoutts wait... we still need #6 which would break the compression-side of the API ;-)

@hvr @dcoutts I think it would be sufficient to export a decompressM that uses foldDecompressStream and some variation of throwM. Explicit exception handling is especially crucial for processing http responses, which are gzipped only if successful. Would you accept such a patch?

@hvr @dcoutts If I understand correctly, the latest version of zlib released on March 8 doesn't carry add this functionality. Is it in the development plans for the foreseeable future, or could you please advise what other zlib/gzip streaming bindings expose a monadic interface that throws relevant exceptions ?

hvr commented

I think there's a good chance that the next one will... personally I'd like to see zlib's API be harmonised with http://hackage.haskell.org/package/lzma-0.0.0.3/docs/Codec-Compression-Lzma.html but I still need to negotiate w/ Duncan :-)

@dcoutts @hvr is there anything I can do to help with this issue? Perhaps you have an idea on how should the common zlib/lzma interface evolve and can advise for a PR? Thanks!

Ping !

What are the plans? I would appreciate either providing a safe decompress function or moving streaming functions out of .Internal. So that I feel more confident when using them...

No plans, unless someone is passionate enough to prepare a PR for discussion.

But if it's no longer "internal", I can sleep sound not being afraid that one day it will be changed without a warning.

I don't follow. What makes you think that Codec.Compression.Zlib.Internal is less stable than the rest of the package?

I still don't get the link between "internal" aka "low-level interface" and supposed stability.

Any part of this package could be changed at any time, no hard guarantees indeed. The only promise is that such change will be properly reflected by bumping the major version, as PVP requires, and *.Internal namespace is no different.

Fixed in 10f8392.