Commit cd941890 authored by Falco Peijnenburg's avatar Falco Peijnenburg

Return error when evaluation failed

parent 6362b9b1
...@@ -309,7 +309,10 @@ replyTo _ interface req@ExecuteRequest { getCode = code } replyHeader state = do ...@@ -309,7 +309,10 @@ replyTo _ interface req@ExecuteRequest { getCode = code } replyHeader state = do
-- Run code and publish to the frontend as we go. -- Run code and publish to the frontend as we go.
let widgetMessageHandler = widgetHandler send replyHeader let widgetMessageHandler = widgetHandler send replyHeader
publish = publishResult send replyHeader displayed updateNeeded pOut (usePager state) publish = publishResult send replyHeader displayed updateNeeded pOut (usePager state)
updatedState <- evaluate state (T.unpack code) publish widgetMessageHandler (updatedState, errorOccurred) <- evaluate state (T.unpack code) publish widgetMessageHandler
let executeReplyStatus = case errorOccurred of
Success -> Ok
Failure -> Err
-- Take pager output if we're using the pager. -- Take pager output if we're using the pager.
pager <- if usePager state pager <- if usePager state
...@@ -320,7 +323,7 @@ replyTo _ interface req@ExecuteRequest { getCode = code } replyHeader state = do ...@@ -320,7 +323,7 @@ replyTo _ interface req@ExecuteRequest { getCode = code } replyHeader state = do
{ header = replyHeader { header = replyHeader
, pagerOutput = pager , pagerOutput = pager
, executionCounter = execCount , executionCounter = execCount
, status = Ok , status = executeReplyStatus
}) })
-- Check for a trailing empty line. If it doesn't exist, we assume the code is incomplete, -- Check for a trailing empty line. If it doesn't exist, we assume the code is incomplete,
......
...@@ -383,7 +383,7 @@ evaluate :: KernelState -- ^ The kernel state. ...@@ -383,7 +383,7 @@ evaluate :: KernelState -- ^ The kernel state.
-> String -- ^ Haskell code or other interpreter commands. -> String -- ^ Haskell code or other interpreter commands.
-> Publisher -- ^ Function used to publish data outputs. -> Publisher -- ^ Function used to publish data outputs.
-> (KernelState -> [WidgetMsg] -> IO KernelState) -- ^ Function to handle widget messages -> (KernelState -> [WidgetMsg] -> IO KernelState) -- ^ Function to handle widget messages
-> Interpreter KernelState -> Interpreter (KernelState, ErrorOccurred)
evaluate kernelState code output widgetHandler = do evaluate kernelState code output widgetHandler = do
cmds <- parseString (cleanString code) cmds <- parseString (cleanString code)
let execCount = getExecutionCounter kernelState let execCount = getExecutionCounter kernelState
...@@ -393,7 +393,7 @@ evaluate kernelState code output widgetHandler = do ...@@ -393,7 +393,7 @@ evaluate kernelState code output widgetHandler = do
justError _ = Nothing justError _ = Nothing
errs = mapMaybe (justError . unloc) cmds errs = mapMaybe (justError . unloc) cmds
updated <- case errs of (updated, errorOccurred) <- case errs of
-- Only run things if there are no parse errors. -- Only run things if there are no parse errors.
[] -> do [] -> do
...@@ -412,16 +412,16 @@ evaluate kernelState code output widgetHandler = do ...@@ -412,16 +412,16 @@ evaluate kernelState code output widgetHandler = do
liftIO $ output liftIO $ output
(FinalResult (evalResult out) [] []) (FinalResult (evalResult out) [] [])
(evalStatus out) (evalStatus out)
return kernelState return (kernelState, Failure)
return updated { getExecutionCounter = execCount + 1 } return (updated { getExecutionCounter = execCount + 1 }, errorOccurred)
where where
noResults (Display res) = null res noResults (Display res) = null res
noResults (ManyDisplay res) = all noResults res noResults (ManyDisplay res) = all noResults res
runUntilFailure :: KernelState -> [CodeBlock] -> Interpreter KernelState runUntilFailure :: KernelState -> [CodeBlock] -> Interpreter (KernelState, ErrorOccurred)
runUntilFailure state [] = return state runUntilFailure state [] = return (state, Success)
runUntilFailure state (cmd:rest) = do runUntilFailure state (cmd:rest) = do
evalOut <- evalCommand output cmd state evalOut <- evalCommand output cmd state
...@@ -458,7 +458,7 @@ evaluate kernelState code output widgetHandler = do ...@@ -458,7 +458,7 @@ evaluate kernelState code output widgetHandler = do
case evalStatus evalOut of case evalStatus evalOut of
Success -> runUntilFailure newState rest Success -> runUntilFailure newState rest
Failure -> return newState Failure -> return (newState, Failure)
storeItCommand execCount = Statement $ printf "let it%d = it" execCount storeItCommand execCount = Statement $ printf "let it%d = it" execCount
......
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