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 #-}
module Main where
import qualified Codec.Compression.Lzma as Lzma
import Control.Exception (catch)
import qualified Data.ByteString.Lazy as BSL
readXz :: FilePath -> IO BSL.ByteString
readXz f = do
let params = Lzma.defaultDecompressParams {Lzma.decompressMemLimit = maxBound}
Lzma.decompressWith params <$> BSL.readFile f
handleErr :: Lzma.LzmaRet -> IO BSL.ByteString
handleErr e = do
print e
return ""
main :: IO ()
main = do
a <- catch (readXz "jumbled.xz") handleErr
print a
This will not fail gracefully. What am I missing, here?
I can't quite figure out how to catch decompression errors. I'd expect the usual mechanisms,
tryorcatch, to work. ButLzmaRetExceptions thrown bydecompresscannot be caught. Here's my example (create ajumbled.xzfile with silly content):{-# LANGUAGE OverloadedStrings #-} module Main where import qualified Codec.Compression.Lzma as Lzma import Control.Exception (catch) import qualified Data.ByteString.Lazy as BSL readXz :: FilePath -> IO BSL.ByteString readXz f = do let params = Lzma.defaultDecompressParams {Lzma.decompressMemLimit = maxBound} Lzma.decompressWith params <$> BSL.readFile f handleErr :: Lzma.LzmaRet -> IO BSL.ByteString handleErr e = do print e return "" main :: IO () main = do a <- catch (readXz "jumbled.xz") handleErr print aThis will not fail gracefully. What am I missing, here?