Show the position when an assertion fails
This commit is contained in:
parent
1e2bd9eb2f
commit
ecdb798560
|
@ -77,7 +77,7 @@ type MonadNix e m =
|
|||
Typeable m, MonadVar m, MonadEffects m, MonadFix m, MonadCatch m,
|
||||
Alternative m)
|
||||
|
||||
data ExecFrame m = Assertion (NValue m)
|
||||
data ExecFrame m = Assertion SrcSpan (NValue m)
|
||||
deriving (Show, Typeable)
|
||||
|
||||
instance Typeable m => Frame (ExecFrame m)
|
||||
|
@ -189,13 +189,13 @@ instance MonadNix e m => MonadEval (NValue m) m where
|
|||
then addProvenance (\t -> Provenance scope (NIf_ span (Just c) (Just t) Nothing)) <$> t
|
||||
else addProvenance (\f -> Provenance scope (NIf_ span (Just c) Nothing (Just f))) <$> f
|
||||
|
||||
evalAssert c body = fromValue c >>= \b ->
|
||||
evalAssert c body = fromValue c >>= \b -> do
|
||||
span <- currentPos
|
||||
if b
|
||||
then do
|
||||
scope <- currentScopes
|
||||
span <- currentPos
|
||||
addProvenance (\b -> Provenance scope (NAssert_ span (Just c) (Just b))) <$> body
|
||||
else nverr $ Assertion c
|
||||
else nverr $ Assertion span c
|
||||
|
||||
evalApp f x = do
|
||||
scope <- currentScopes
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
{-# LANGUAGE ConstraintKinds #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
|
@ -27,11 +26,11 @@ posAndMsg beg msg =
|
|||
|
||||
renderLocation :: MonadFile m => SrcSpan -> Doc -> m Doc
|
||||
renderLocation (SrcSpan beg@(SourcePos "<string>" _ _) _) msg =
|
||||
return $ text $ parseErrorPretty @Char (posAndMsg beg msg)
|
||||
return $ text $ init $ parseErrorPretty @Char (posAndMsg beg msg)
|
||||
|
||||
renderLocation (SrcSpan beg@(SourcePos path _ _) _) msg = do
|
||||
contents <- Nix.Render.readFile path
|
||||
return $ text $ parseErrorPretty' contents (posAndMsg beg msg)
|
||||
return $ text $ init $ parseErrorPretty' contents (posAndMsg beg msg)
|
||||
|
||||
{-
|
||||
-}
|
||||
|
|
|
@ -138,11 +138,12 @@ renderExecFrame :: (MonadReader e m, Has e Options, MonadVar m, MonadFile m)
|
|||
renderExecFrame _level f = do
|
||||
opts :: Options <- asks (view hasLens)
|
||||
(:[]) <$> case f of
|
||||
Assertion v
|
||||
Assertion ann v
|
||||
| values opts ->
|
||||
(text "Assertion failed:" </>) <$> renderNValueProv v
|
||||
renderLocation ann =<<
|
||||
((text "Assertion failed:" </>) <$> renderNValueProv v)
|
||||
| otherwise ->
|
||||
pure $ text "Assertion failed"
|
||||
renderLocation ann (text "Assertion failed")
|
||||
|
||||
renderThunkLoop :: (MonadReader e m, Has e Options, MonadFile m)
|
||||
=> NixLevel -> ThunkLoop -> m [Doc]
|
||||
|
|
Loading…
Reference in a new issue