Skip to content

Commit

Permalink
IHaskell.Eval.Evaluate: catch exceptions in extractValue (#1486)
Browse files Browse the repository at this point in the history
* IHaskell.Eval.Evaluate: catch exceptions in extractValue

* IHaskell.Eval.Evaluate: only catch exceptions for GHC >=9.0
  • Loading branch information
vaibhavsagar committed Apr 21, 2024
1 parent 8ceec8b commit b223a6c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/IHaskell/Eval/Evaluate.hs
Expand Up @@ -516,10 +516,19 @@ evaluate kernelState code output widgetHandler = do
-- from inside the notebook environment.
extractValue :: Typeable a => String -> Interpreter (Either String a)
extractValue expr = do
#if MIN_VERSION_ghc(9,0,0)
compiled <- gcatch (Right <$> dynCompileExpr expr) (\exc -> return (Left (show exc)))
case compiled of
Left exc -> return (Left exc)
Right dyn -> case fromDynamic dyn of
Nothing -> return (Left multipleIHaskells)
Just result -> return (Right result)
#else
compiled <- dynCompileExpr expr
case fromDynamic compiled of
Nothing -> return (Left multipleIHaskells)
Just result -> return (Right result)
#endif

where
multipleIHaskells =
Expand Down

0 comments on commit b223a6c

Please sign in to comment.