Commit 616bc00e authored by Vaibhav Sagar's avatar Vaibhav Sagar

Attempt to set error status

parent 3b0936d4
...@@ -78,7 +78,7 @@ matrix: ...@@ -78,7 +78,7 @@ matrix:
# Run the notebook to regenerate the outputs, then compare the new notebook to the old one. # Run the notebook to regenerate the outputs, then compare the new notebook to the old one.
stack install --fast stack install --fast
stack exec -- ihaskell install --stack stack exec -- ihaskell install --stack
stack exec -- jupyter nbconvert --to=notebook --execute --stdout notebooks/IHaskell.ipynb > ~/ihaskell-out.ipynb stack exec -- jupyter nbconvert --to=notebook --execute --allow-errors --stdout notebooks/IHaskell.ipynb > ~/ihaskell-out.ipynb
# Images are rendered differently on different systems, so filter them out in the comparison # Images are rendered differently on different systems, so filter them out in the comparison
diff <(egrep -v 'image/png|version|pygments' ~/ihaskell-out.ipynb) <(egrep -v 'image/png|version|pygments' notebooks/IHaskell.ipynb) diff <(egrep -v 'image/png|version|pygments' ~/ihaskell-out.ipynb) <(egrep -v 'image/png|version|pygments' notebooks/IHaskell.ipynb)
...@@ -158,7 +158,7 @@ matrix: ...@@ -158,7 +158,7 @@ matrix:
# Run the notebook to regenerate the outputs, then compare the new notebook to the old one. # Run the notebook to regenerate the outputs, then compare the new notebook to the old one.
stack install --fast stack install --fast
stack exec -- ihaskell install --stack stack exec -- ihaskell install --stack
stack exec -- jupyter nbconvert --to=notebook --execute --stdout notebooks/IHaskell.ipynb > ~/ihaskell-out.ipynb stack exec -- jupyter nbconvert --to=notebook --execute --allow-errors --stdout notebooks/IHaskell.ipynb > ~/ihaskell-out.ipynb
# Images are rendered differently on different systems, so filter them out in the comparison # Images are rendered differently on different systems, so filter them out in the comparison
diff <(egrep -v 'image/png|version|pygments' ~/ihaskell-out.ipynb) <(egrep -v 'image/png|version|pygments' notebooks/IHaskell.ipynb) diff <(egrep -v 'image/png|version|pygments' ~/ihaskell-out.ipynb) <(egrep -v 'image/png|version|pygments' notebooks/IHaskell.ipynb)
...@@ -238,7 +238,7 @@ matrix: ...@@ -238,7 +238,7 @@ matrix:
# Run the notebook to regenerate the outputs, then compare the new notebook to the old one. # Run the notebook to regenerate the outputs, then compare the new notebook to the old one.
stack install --fast stack install --fast
stack exec -- ihaskell install --stack stack exec -- ihaskell install --stack
stack exec -- jupyter nbconvert --to=notebook --execute --stdout notebooks/IHaskell.ipynb > ~/ihaskell-out.ipynb stack exec -- jupyter nbconvert --to=notebook --execute --allow-errors --stdout notebooks/IHaskell.ipynb > ~/ihaskell-out.ipynb
# Images are rendered differently on different systems, so filter them out in the comparison # Images are rendered differently on different systems, so filter them out in the comparison
diff <(egrep -v 'image/png|version|pygments' ~/ihaskell-out.ipynb) <(egrep -v 'image/png|version|pygments' notebooks/IHaskell.ipynb) diff <(egrep -v 'image/png|version|pygments' ~/ihaskell-out.ipynb) <(egrep -v 'image/png|version|pygments' notebooks/IHaskell.ipynb)
...@@ -318,7 +318,7 @@ matrix: ...@@ -318,7 +318,7 @@ matrix:
# Run the notebook to regenerate the outputs, then compare the new notebook to the old one. # Run the notebook to regenerate the outputs, then compare the new notebook to the old one.
stack install --fast stack install --fast
stack exec -- ihaskell install --stack stack exec -- ihaskell install --stack
stack exec -- jupyter nbconvert --to=notebook --execute --stdout notebooks/IHaskell.ipynb > ~/ihaskell-out.ipynb stack exec -- jupyter nbconvert --to=notebook --execute --allow-errors --stdout notebooks/IHaskell.ipynb > ~/ihaskell-out.ipynb
# Images are rendered differently on different systems, so filter them out in the comparison # Images are rendered differently on different systems, so filter them out in the comparison
diff <(egrep -v 'image/png|version|pygments' ~/ihaskell-out.ipynb) <(egrep -v 'image/png|version|pygments' notebooks/IHaskell.ipynb) diff <(egrep -v 'image/png|version|pygments' ~/ihaskell-out.ipynb) <(egrep -v 'image/png|version|pygments' notebooks/IHaskell.ipynb)
...@@ -352,7 +352,7 @@ matrix: ...@@ -352,7 +352,7 @@ matrix:
ihaskell-plot ihaskell-plot
ihaskell-static-canvas ihaskell-static-canvas
])' ])'
- result/bin/ihaskell-nbconvert --to=notebook --execute --stdout notebooks/IHaskell.ipynb > ~/ihaskell-out.ipynb - result/bin/ihaskell-nbconvert --to=notebook --execute --allow-errors --stdout notebooks/IHaskell.ipynb > ~/ihaskell-out.ipynb
- diff <(egrep -v 'image/png|version|pygments' ~/ihaskell-out.ipynb) <(egrep -v 'image/png|version|pygments' notebooks/IHaskell.ipynb) - diff <(egrep -v 'image/png|version|pygments' ~/ihaskell-out.ipynb) <(egrep -v 'image/png|version|pygments' notebooks/IHaskell.ipynb)
- language: nix - language: nix
dist: xenial dist: xenial
...@@ -383,5 +383,5 @@ matrix: ...@@ -383,5 +383,5 @@ matrix:
ihaskell-plot ihaskell-plot
ihaskell-static-canvas ihaskell-static-canvas
])' ])'
- result/bin/ihaskell-nbconvert --to=notebook --execute --stdout notebooks/IHaskell.ipynb > ~/ihaskell-out.ipynb - result/bin/ihaskell-nbconvert --to=notebook --execute --allow-errors --stdout notebooks/IHaskell.ipynb > ~/ihaskell-out.ipynb
- diff <(egrep -v 'image/png|version|pygments' ~/ihaskell-out.ipynb) <(egrep -v 'image/png|version|pygments' notebooks/IHaskell.ipynb) - diff <(egrep -v 'image/png|version|pygments' ~/ihaskell-out.ipynb) <(egrep -v 'image/png|version|pygments' notebooks/IHaskell.ipynb)
...@@ -148,7 +148,7 @@ executeErrorParser = requestParser $ \obj -> do ...@@ -148,7 +148,7 @@ executeErrorParser = requestParser $ \obj -> do
traceback <- obj .: "traceback" traceback <- obj .: "traceback"
ename <- obj .: "ename" ename <- obj .: "ename"
evalue <- obj .: "evalue" evalue <- obj .: "evalue"
return $ ExecuteError noHeader [] traceback ename evalue return $ ExecuteError noHeader traceback ename evalue
makeDisplayDatas :: Object -> [DisplayData] makeDisplayDatas :: Object -> [DisplayData]
makeDisplayDatas dataDict = [DisplayData (read $ unpack mimeType) content | (mimeType, String content) <- HM.toList makeDisplayDatas dataDict = [DisplayData (read $ unpack mimeType) content | (mimeType, String content) <- HM.toList
......
...@@ -378,7 +378,6 @@ data Message = ...@@ -378,7 +378,6 @@ data Message =
-- | An error reply to an execute request -- | An error reply to an execute request
ExecuteError ExecuteError
{ header :: MessageHeader { header :: MessageHeader
, pagerOutput :: [DisplayData] -- ^ The mimebundles to display in the pager.
, traceback :: [Text] , traceback :: [Text]
, ename :: Text , ename :: Text
, evalue :: Text , evalue :: Text
...@@ -561,6 +560,13 @@ instance ToJSON Message where ...@@ -561,6 +560,13 @@ instance ToJSON Message where
, "data" .= object (map displayDataToJson o) , "data" .= object (map displayDataToJson o)
] ]
] ]
toJSON ExecuteError { header = header, traceback = traceback, ename = ename, evalue = evalue } =
object
[ "header" .= show header
, "traceback" .= map toJSON traceback
, "ename" .= ename
, "evalue" .= evalue
]
toJSON PublishStatus { executionState = executionState } = toJSON PublishStatus { executionState = executionState } =
object ["execution_state" .= executionState] object ["execution_state" .= executionState]
toJSON PublishStream { streamType = streamType, streamContent = content } = toJSON PublishStream { streamType = streamType, streamContent = content } =
......
...@@ -151,7 +151,7 @@ runKernel kOpts profileSrc = do ...@@ -151,7 +151,7 @@ runKernel kOpts profileSrc = do
kernelState { supportLibrariesAvailable = hasSupportLibraries } kernelState { supportLibrariesAvailable = hasSupportLibraries }
-- Initialize the context by evaluating everything we got from the command line flags. -- Initialize the context by evaluating everything we got from the command line flags.
let noPublish _ = return () let noPublish _ _ = return ()
noWidget s _ = return s noWidget s _ = return s
evaluator line = void $ do evaluator line = void $ do
-- Create a new state each time. -- Create a new state each time.
...@@ -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 []) [] liftIO $ publish (FinalResult disp (if toUsePager then pgrOut else []) []) True
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 []) [] liftIO $ publish (FinalResult disp (if toUsePager then pgrOut else []) []) True
return kernelState { openComms = Map.delete uuid widgets } return kernelState { openComms = Map.delete uuid widgets }
_ -> _ ->
-- Only sensible thing to do. -- Only sensible thing to do.
......
...@@ -126,7 +126,7 @@ testInterpret v = interpret GHC.Paths.libdir False (const v) ...@@ -126,7 +126,7 @@ testInterpret v = interpret GHC.Paths.libdir False (const v)
-- | Evaluation function for testing. -- | Evaluation function for testing.
testEvaluate :: String -> IO () testEvaluate :: String -> IO ()
testEvaluate str = void $ testInterpret $ testEvaluate str = void $ testInterpret $
evaluate defaultKernelState str (const $ return ()) (\state _ -> return state) evaluate defaultKernelState str (\_ _ -> return ()) (\state _ -> return state)
-- | Run an interpreting action. This is effectively runGhc with initialization and importing. First -- | Run an interpreting action. This is effectively runGhc with initialization and importing. First
-- argument indicates whether `stdin` is handled specially, which cannot be done in a testing -- argument indicates whether `stdin` is handled specially, which cannot be done in a testing
...@@ -249,8 +249,9 @@ initializeItVariable = ...@@ -249,8 +249,9 @@ initializeItVariable =
void $ execStmt "let it = ()" execOptions void $ execStmt "let it = ()" execOptions
-- | 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). -- (true) or intermediate (false). The second argument indicates whether the evaluation
type Publisher = (EvaluationResult -> IO ()) -- completed successfully (true) or an error occurred (false).
type Publisher = (EvaluationResult -> Bool -> IO ())
-- | Output of a command evaluation. -- | Output of a command evaluation.
data EvalOut = data EvalOut =
...@@ -277,6 +278,11 @@ cleanString istr = if allBrackets ...@@ -277,6 +278,11 @@ 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.
...@@ -298,14 +304,16 @@ evaluate kernelState code output widgetHandler = do ...@@ -298,14 +304,16 @@ 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 [] [] output (FinalResult lintSuggestions [] []) True
runUntilFailure kernelState (map unloc cmds ++ [storeItCommand execCount]) runUntilFailure kernelState (map unloc cmds ++ [storeItCommand execCount])
-- Print all parse errors. -- Print all parse errors.
_ -> do _ -> do
forM_ errs $ \err -> do forM_ errs $ \err -> do
out <- evalCommand output err kernelState out <- evalCommand output err kernelState
liftIO $ output $ FinalResult (evalResult out) [] [] liftIO $ output
(FinalResult (evalResult out) [] [])
(successStatus $ evalStatus out)
return kernelState return kernelState
return updated { getExecutionCounter = execCount + 1 } return updated { getExecutionCounter = execCount + 1 }
...@@ -338,7 +346,9 @@ evaluate kernelState code output widgetHandler = do ...@@ -338,7 +346,9 @@ evaluate kernelState code output widgetHandler = do
-- Output things only if they are non-empty. -- Output things only if they are non-empty.
unless (noResults result && null (evalPager evalOut)) $ unless (noResults result && null (evalPager evalOut)) $
liftIO $ output $ FinalResult result (evalPager evalOut) [] liftIO $ output
(FinalResult result (evalPager evalOut) [])
(successStatus $ evalStatus evalOut)
let tempMsgs = evalMsgs evalOut let tempMsgs = evalMsgs evalOut
tempState = evalState evalOut { evalMsgs = [] } tempState = evalState evalOut { evalMsgs = [] }
...@@ -693,7 +703,7 @@ evalCommand publish (Directive ShellCmd cmd) state = wrapExecution state $ ...@@ -693,7 +703,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 >>= output readMVar outputAccum >>= flip output True
loop loop
Just exitCode -> do Just exitCode -> do
next <- readChars pipe "" maxSize next <- readChars pipe "" maxSize
...@@ -1222,7 +1232,7 @@ evalStatementOrIO publish state cmd = do ...@@ -1222,7 +1232,7 @@ evalStatementOrIO publish state cmd = do
CapturedIO _ -> CapturedIO _ ->
write state "Evaluating Action" write state "Evaluating Action"
(printed, result) <- capturedEval output cmd (printed, result) <- capturedEval (flip output True) cmd
case result of case result of
ExecComplete (Right names) _ -> do ExecComplete (Right names) _ -> do
dflags <- getSessionDynFlags dflags <- getSessionDynFlags
......
...@@ -26,8 +26,9 @@ publishResult :: (Message -> IO ()) -- ^ A function to send messages ...@@ -26,8 +26,9 @@ 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
-> IO () -> IO ()
publishResult send replyHeader displayed updateNeeded poutput upager result = do publishResult send replyHeader displayed updateNeeded poutput upager result success = do
let final = let final =
case result of case result of
IntermediateResult{} -> False IntermediateResult{} -> False
......
...@@ -24,7 +24,7 @@ eval :: String -> IO ([Display], String) ...@@ -24,7 +24,7 @@ eval :: String -> IO ([Display], String)
eval string = do eval string = do
outputAccum <- newIORef [] outputAccum <- newIORef []
pagerAccum <- newIORef [] pagerAccum <- newIORef []
let publish evalResult = let publish evalResult _ =
case evalResult of case evalResult of
IntermediateResult{} -> return () IntermediateResult{} -> return ()
FinalResult outs page _ -> do FinalResult outs page _ -> do
......
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