Commit b956d8fb authored by Vaibhav Sagar's avatar Vaibhav Sagar

Move ErrorOccurred to IHaskell.Types

parent b2bf84ee
...@@ -12,7 +12,7 @@ import qualified Data.ByteString.Lazy as LBS ...@@ -12,7 +12,7 @@ import qualified Data.ByteString.Lazy as LBS
-- Standard library imports. -- Standard library imports.
import Control.Concurrent.Chan import Control.Concurrent.Chan
import Control.Arrow (second) import Control.Arrow (second)
import Data.Aeson import Data.Aeson hiding (Success)
import System.Process (readProcess, readProcessWithExitCode) import System.Process (readProcess, readProcessWithExitCode)
import System.Exit (exitSuccess, ExitCode(ExitSuccess)) import System.Exit (exitSuccess, ExitCode(ExitSuccess))
import Control.Exception (try, SomeException) import Control.Exception (try, SomeException)
...@@ -429,12 +429,12 @@ handleComm send kernelState req replyHeader = do ...@@ -429,12 +429,12 @@ handleComm send kernelState req replyHeader = do
CommDataMessage -> do CommDataMessage -> do
disp <- run $ comm widget dat communicate disp <- run $ comm widget dat communicate
pgrOut <- liftIO $ readMVar pOut pgrOut <- liftIO $ readMVar pOut
liftIO $ publish (FinalResult disp (if toUsePager then pgrOut else []) []) True liftIO $ publish (FinalResult disp (if toUsePager then pgrOut else []) []) Success
return kernelState return kernelState
CommCloseMessage -> do CommCloseMessage -> do
disp <- run $ close widget dat disp <- run $ close widget dat
pgrOut <- liftIO $ readMVar pOut pgrOut <- liftIO $ readMVar pOut
liftIO $ publish (FinalResult disp (if toUsePager then pgrOut else []) []) True liftIO $ publish (FinalResult disp (if toUsePager then pgrOut else []) []) Success
return kernelState { openComms = Map.delete uuid widgets } return kernelState { openComms = Map.delete uuid widgets }
_ -> _ ->
-- Only sensible thing to do. -- Only sensible thing to do.
......
...@@ -70,9 +70,6 @@ import Data.Version (versionBranch) ...@@ -70,9 +70,6 @@ import Data.Version (versionBranch)
#endif #endif
data ErrorOccurred = Success
| Failure
deriving (Show, Eq)
-- | Set GHC's verbosity for debugging -- | Set GHC's verbosity for debugging
ghcVerbosity :: Maybe Int ghcVerbosity :: Maybe Int
...@@ -250,8 +247,8 @@ initializeItVariable = ...@@ -250,8 +247,8 @@ initializeItVariable =
-- | Publisher for IHaskell outputs. The first argument indicates whether this output is final -- | Publisher for IHaskell outputs. The first argument indicates whether this output is final
-- (true) or intermediate (false). The second argument indicates whether the evaluation -- (true) or intermediate (false). The second argument indicates whether the evaluation
-- completed successfully (true) or an error occurred (false). -- completed successfully (Success) or an error occurred (Failure).
type Publisher = (EvaluationResult -> Bool -> IO ()) type Publisher = (EvaluationResult -> ErrorOccurred -> IO ())
-- | Output of a command evaluation. -- | Output of a command evaluation.
data EvalOut = data EvalOut =
...@@ -278,11 +275,6 @@ cleanString istr = if allBrackets ...@@ -278,11 +275,6 @@ cleanString istr = if allBrackets
-- should never happen: -- should never happen:
removeBracket other = error $ "Expected bracket as first char, but got string: " ++ other removeBracket other = error $ "Expected bracket as first char, but got string: " ++ other
-- | Converts Success/Failure to a boolean to set the output cell type.
successStatus :: ErrorOccurred -> Bool
successStatus Success = True
successStatus Failure = False
-- | Evaluate some IPython input code. -- | Evaluate some IPython input code.
evaluate :: KernelState -- ^ The kernel state. evaluate :: KernelState -- ^ The kernel state.
-> String -- ^ Haskell code or other interpreter commands. -> String -- ^ Haskell code or other interpreter commands.
...@@ -304,7 +296,7 @@ evaluate kernelState code output widgetHandler = do ...@@ -304,7 +296,7 @@ evaluate kernelState code output widgetHandler = do
when (getLintStatus kernelState /= LintOff) $ liftIO $ do when (getLintStatus kernelState /= LintOff) $ liftIO $ do
lintSuggestions <- lint cmds lintSuggestions <- lint cmds
unless (noResults lintSuggestions) $ unless (noResults lintSuggestions) $
output (FinalResult lintSuggestions [] []) True output (FinalResult lintSuggestions [] []) Success
runUntilFailure kernelState (map unloc cmds ++ [storeItCommand execCount]) runUntilFailure kernelState (map unloc cmds ++ [storeItCommand execCount])
-- Print all parse errors. -- Print all parse errors.
...@@ -313,7 +305,7 @@ evaluate kernelState code output widgetHandler = do ...@@ -313,7 +305,7 @@ evaluate kernelState code output widgetHandler = do
out <- evalCommand output err kernelState out <- evalCommand output err kernelState
liftIO $ output liftIO $ output
(FinalResult (evalResult out) [] []) (FinalResult (evalResult out) [] [])
(successStatus $ evalStatus out) (evalStatus out)
return kernelState return kernelState
return updated { getExecutionCounter = execCount + 1 } return updated { getExecutionCounter = execCount + 1 }
...@@ -348,7 +340,7 @@ evaluate kernelState code output widgetHandler = do ...@@ -348,7 +340,7 @@ evaluate kernelState code output widgetHandler = do
unless (noResults result && null (evalPager evalOut)) $ unless (noResults result && null (evalPager evalOut)) $
liftIO $ output liftIO $ output
(FinalResult result (evalPager evalOut) []) (FinalResult result (evalPager evalOut) [])
(successStatus $ evalStatus evalOut) (evalStatus evalOut)
let tempMsgs = evalMsgs evalOut let tempMsgs = evalMsgs evalOut
tempState = evalState evalOut { evalMsgs = [] } tempState = evalState evalOut { evalMsgs = [] }
...@@ -703,7 +695,7 @@ evalCommand publish (Directive ShellCmd cmd) state = wrapExecution state $ ...@@ -703,7 +695,7 @@ evalCommand publish (Directive ShellCmd cmd) state = wrapExecution state $
case mExitCode of case mExitCode of
Nothing -> do Nothing -> do
-- Write to frontend and repeat. -- Write to frontend and repeat.
readMVar outputAccum >>= flip output True readMVar outputAccum >>= flip output Success
loop loop
Just exitCode -> do Just exitCode -> do
next <- readChars pipe "" maxSize next <- readChars pipe "" maxSize
...@@ -1232,7 +1224,7 @@ evalStatementOrIO publish state cmd = do ...@@ -1232,7 +1224,7 @@ evalStatementOrIO publish state cmd = do
CapturedIO _ -> CapturedIO _ ->
write state "Evaluating Action" write state "Evaluating Action"
(printed, result) <- capturedEval (flip output True) cmd (printed, result) <- capturedEval (flip output Success) cmd
case result of case result of
ExecComplete (Right names) _ -> do ExecComplete (Right names) _ -> do
dflags <- getSessionDynFlags dflags <- getSessionDynFlags
......
...@@ -26,7 +26,7 @@ publishResult :: (Message -> IO ()) -- ^ A function to send messages ...@@ -26,7 +26,7 @@ publishResult :: (Message -> IO ()) -- ^ A function to send messages
-> MVar [DisplayData] -- ^ A MVar to use for storing pager output -> MVar [DisplayData] -- ^ A MVar to use for storing pager output
-> Bool -- ^ Whether to use the pager -> Bool -- ^ Whether to use the pager
-> EvaluationResult -- ^ The evaluation result -> EvaluationResult -- ^ The evaluation result
-> Bool -- ^ Whether evaluation completed successfully -> ErrorOccurred -- ^ Whether evaluation completed successfully
-> IO () -> IO ()
publishResult send replyHeader displayed updateNeeded poutput upager result success = do publishResult send replyHeader displayed updateNeeded poutput upager result success = do
let final = let final =
...@@ -70,9 +70,13 @@ publishResult send replyHeader displayed updateNeeded poutput upager result succ ...@@ -70,9 +70,13 @@ publishResult send replyHeader displayed updateNeeded poutput upager result succ
sendOutput uniqueLabel (ManyDisplay manyOuts) = sendOutput uniqueLabel (ManyDisplay manyOuts) =
mapM_ (sendOutput uniqueLabel) manyOuts mapM_ (sendOutput uniqueLabel) manyOuts
sendOutput uniqueLabel (Display outs) = do sendOutput uniqueLabel (Display outs) = case success of
Success -> do
hdr <- dupHeader replyHeader DisplayDataMessage hdr <- dupHeader replyHeader DisplayDataMessage
send $ PublishDisplayData hdr (map (makeUnique uniqueLabel . prependCss) outs) Nothing send $ PublishDisplayData hdr (map (makeUnique uniqueLabel . prependCss) outs) Nothing
Failure -> do
hdr <- dupHeader replyHeader ExecuteErrorMessage
send $ ExecuteError hdr [T.pack (extractPlain outs)] "" ""
prependCss (DisplayData MimeHtml h) = prependCss (DisplayData MimeHtml h) =
DisplayData MimeHtml $ mconcat ["<style>", T.pack ihaskellCSS, "</style>", h] DisplayData MimeHtml $ mconcat ["<style>", T.pack ihaskellCSS, "</style>", h]
......
...@@ -18,6 +18,7 @@ module IHaskell.Types ( ...@@ -18,6 +18,7 @@ module IHaskell.Types (
StreamType(..), StreamType(..),
MimeType(..), MimeType(..),
DisplayData(..), DisplayData(..),
ErrorOccurred(..),
EvaluationResult(..), EvaluationResult(..),
evaluationOutputs, evaluationOutputs,
ExecuteReplyStatus(..), ExecuteReplyStatus(..),
...@@ -274,5 +275,9 @@ evaluationOutputs er = ...@@ -274,5 +275,9 @@ evaluationOutputs er =
dupHeader :: MessageHeader -> MessageType -> IO MessageHeader dupHeader :: MessageHeader -> MessageType -> IO MessageHeader
dupHeader hdr messageType = do dupHeader hdr messageType = do
uuid <- liftIO random uuid <- liftIO random
return hdr { mhMessageId = uuid, mhMsgType = messageType } return hdr { mhMessageId = uuid, mhMsgType = messageType }
-- | Whether or not an error occurred.
data ErrorOccurred = Success
| Failure
deriving (Show, Eq)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment