Twinside / Juicy.Pixels

Haskell library to load & save pictures

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'fail' in Either throws exception

17dec opened this issue · comments

commented

I'm relatively new to Haskell, so please excuse me if I'm missing something.

I'm using decodeImage to read an image and am a little confused about its error handling. I expect to get a Left "error" when loading fails for one reason or another, but what I'm seeing is that decodeImage throws an error in some cases. e.g.:

*** Exception (reporting due to +RTS -xc): (THUNK_2_0), stack trace: 
  Codec.Picture.Tga.prepareUnpacker,
  called from Codec.Picture.Tga.unparse,
  called from Codec.Picture.Tga.decodeTgaWithPaletteAndMetadata,
  called from Codec.Picture.eitherLoad.inner,
  called from Codec.Picture.eitherLoad,
  called from Codec.Picture.decodeImageWithPaletteAndMetadata,
  called from Codec.Picture.decodeImageWithMetadata,
  called from Codec.Picture.decodeImage,
  [..]
Invalid bit depth (0)

Reading the source code of Tga.prepareUnpacker, it seems to expect that fail "something" makes it return a Left "something", but that's not what I am seeing. The exception is also the behaviour I see in GHCi:

Prelude> Just "string" >> fail "x"
Nothing
Prelude> (Right "string" :: Either String String) >> fail "x"
*** Exception: x

Is this intended behaviour or am I missing a flag somewhere?

Huuuuuuu, this is a bug, I assumed that it was returning Left, but it clearly isn't.

I'm gonna fix this asap