Closed
Description
Original comment: #4740 (comment)
This is a horrible piece of code that is totally incorrect:
cardano-ledger/libs/constrained-generators/src/Constrained/Base.hs
Lines 1285 to 1287 in 51f9cef
-
It will catch all exceptions, including async exceptions. It should have been catching the
ErrorCall
exception instead ofSomeException
, if it needs to catch error calls. -
Moreover this code will not even catch error calls because
seq
happens outside ofcatch
:
ghci> let x = undefined in x `seq` pure x `catch` \e -> putStrLn ("WTH " <> show (e :: SomeException))
*** Exception: Prelude.undefined
CallStack (from HasCallStack):
undefined, called at <interactive>:8:9 in interactive:Ghci2
ghci> let x = undefined in (x `seq` pure x) `catch` \e -> putStrLn ("WTH ==============\n" <> show (e :: SomeException))
WTH ==============
Prelude.undefined
CallStack (from HasCallStack):
undefined, called at <interactive>:10:9 in interactive:Ghci3
- Moreover, using
unsafePerformIO
to catch an exception will lead to non-deterministic execution, which can break referential transparency. In other words it is never safe to catch exceptions in pure code withunsafePerformIO
Originally posted by @lehins in #4740 (comment)
Metadata
Assignees
Labels
No labels