You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can't quite figure out how to catch decompression errors. I'd expect the usual mechanisms, try or catch, to work. But LzmaRet Exceptions thrown by decompress cannot be caught. Here's my example (create a jumbled.xz file with silly content):
{-# LANGUAGE OverloadedStrings #-}
moduleMainwhereimportqualifiedCodec.Compression.LzmaasLzmaimportControl.Exception (catch)
importqualifiedData.ByteString.LazyasBSLreadXz::FilePath->IOBSL.ByteString
readXz f =dolet params =Lzma.defaultDecompressParams {Lzma.decompressMemLimit =maxBound}
Lzma.decompressWith params <$>BSL.readFile f
handleErr::Lzma.LzmaRet->IOBSL.ByteString
handleErr e =doprint e
return""main::IO()
main =do
a <- catch (readXz "jumbled.xz") handleErr
print a
This will not fail gracefully. What am I missing, here?
The text was updated successfully, but these errors were encountered:
A transformer acting on lazy bytestrings and returning a lazy bytestring simply has no ability to signal errors in a well-defined way. This is a fundamental issue w/ lazy ByteStrings. Also BSL.readFile suffers from this issue: some I/O errors may result in exceptions being injected into lazy bytestring chunks.
If you need the ability to handle errors in a well-defined way you should use the incremental api, e.g. compressIO or compressST; or alternatively take a look at the streaming framework bindings mentioned at http://hackage.haskell.org/package/lzma.
I can't quite figure out how to catch decompression errors. I'd expect the usual mechanisms,
try
orcatch
, to work. ButLzmaRet
Exceptions thrown bydecompress
cannot be caught. Here's my example (create ajumbled.xz
file with silly content):This will not fail gracefully. What am I missing, here?
The text was updated successfully, but these errors were encountered: