turtle
turtle copied to clipboard
catch catches error in monad continuation
I have the following code
prog1 :: Shell ()
prog1 = do
echo "prog1"
catch
( do
echo "will be catched"
pure ())
(\(_ :: SomeException) -> do
echo "exception")
prog2 :: IO ()
prog2 = do
echo "prog2"
procs "lll" [] mempty
mainMenu' :: Shell ()
mainMenu' = do
echo "mainMenu"
prog1
liftIO prog2
I would expect that running this will not run the error handler (it will not print "exception). But runnig it prints it
*Main> sh $ mainMenu'
mainMenu
prog1
will be catched
prog2
exception
prog2
*** Exception: lll: createProcess: posix_spawnp: does not exist (No such file or directory)
Doing the same thing in the IO monad works as I expect
I'm on version 1.5.22
Yeah, there's not a good way to fix this, short of removing the MonadCatch instance altogether.
What's happening is that whenever you catch something in Shell the exception handler is catching all exceptions that will ever be raised by that Shell, not just exceptions in the wrapped block.