{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE LambdaCase #-}
module Text.Pandoc.Lua.ErrorConversion
( addContextToException
) where
import HsLua (LuaError, LuaE, top)
import HsLua.Marshalling (resultToEither, runPeek)
import HsLua.Class.Peekable (PeekError (..))
import Text.Pandoc.Error (PandocError (PandocLuaError))
import Text.Pandoc.Lua.Marshaling.PandocError (pushPandocError, peekPandocError)
import qualified Data.Text as T
import qualified HsLua as Lua
addContextToException :: ()
addContextToException :: ()
addContextToException = ()
forall a. HasCallStack => a
undefined
popPandocError :: LuaE PandocError PandocError
popPandocError :: LuaE PandocError PandocError
popPandocError = do
Result PandocError
errResult <- Peek PandocError PandocError
-> LuaE PandocError (Result PandocError)
forall e a. Peek e a -> LuaE e (Result a)
runPeek (Peek PandocError PandocError
-> LuaE PandocError (Result PandocError))
-> Peek PandocError PandocError
-> LuaE PandocError (Result PandocError)
forall a b. (a -> b) -> a -> b
$ Peeker PandocError PandocError
forall e. LuaError e => Peeker e PandocError
peekPandocError StackIndex
top
case Result PandocError -> Either String PandocError
forall a. Result a -> Either String a
resultToEither Result PandocError
errResult of
Right PandocError
x -> PandocError -> LuaE PandocError PandocError
forall (m :: * -> *) a. Monad m => a -> m a
return PandocError
x
Left String
err -> PandocError -> LuaE PandocError PandocError
forall (m :: * -> *) a. Monad m => a -> m a
return (PandocError -> LuaE PandocError PandocError)
-> PandocError -> LuaE PandocError PandocError
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocLuaError (String -> Text
T.pack String
err)
instance LuaError PandocError where
popException :: LuaE PandocError PandocError
popException = LuaE PandocError PandocError
popPandocError
pushException :: PandocError -> LuaE PandocError ()
pushException = PandocError -> LuaE PandocError ()
forall e. LuaError e => Pusher e PandocError
pushPandocError
luaException :: String -> PandocError
luaException = Text -> PandocError
PandocLuaError (Text -> PandocError) -> (String -> Text) -> String -> PandocError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
instance PeekError PandocError where
messageFromException :: PandocError -> String
messageFromException = \case
PandocLuaError Text
m -> Text -> String
T.unpack Text
m
PandocError
err -> PandocError -> String
forall a. Show a => a -> String
show PandocError
err