Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch catches error in monad continuation #421

Open
StillerHarpo opened this issue Mar 13, 2022 · 1 comment
Open

catch catches error in monad continuation #421

StillerHarpo opened this issue Mar 13, 2022 · 1 comment

Comments

@StillerHarpo
Copy link

StillerHarpo commented Mar 13, 2022

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

@Gabriella439
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants