diff options
Diffstat (limited to 'src/Text/Pandoc/Lua/Packages.hs')
-rw-r--r-- | src/Text/Pandoc/Lua/Packages.hs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Lua/Packages.hs b/src/Text/Pandoc/Lua/Packages.hs index 79d42a6d7..4c3b9d79d 100644 --- a/src/Text/Pandoc/Lua/Packages.hs +++ b/src/Text/Pandoc/Lua/Packages.hs @@ -1,4 +1,5 @@ {-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE ScopedTypeVariables #-} {- | Module : Text.Pandoc.Lua.Packages @@ -14,9 +15,11 @@ module Text.Pandoc.Lua.Packages ( installPandocPackageSearcher ) where +import Control.Monad.Catch (try) import Control.Monad (forM_) import Data.ByteString (ByteString) import Foreign.Lua (Lua, NumResults) +import Text.Pandoc.Error (PandocError) import Text.Pandoc.Class.PandocMonad (readDataFile) import Text.Pandoc.Lua.PandocLua (PandocLua, liftPandocLua) @@ -58,8 +61,11 @@ pandocPackageSearcher pkgName = return 1 searchPureLuaLoader = do let filename = pkgName ++ ".lua" - script <- readDataFile filename - pushWrappedHsFun (loadStringAsPackage pkgName script) + try (readDataFile filename) >>= \case + Right script -> pushWrappedHsFun (loadStringAsPackage pkgName script) + Left (_ :: PandocError) -> liftPandocLua $ do + Lua.push ("\n\tno file '" ++ filename ++ "' in pandoc's datadir") + return (1 :: NumResults) loadStringAsPackage :: String -> ByteString -> Lua NumResults loadStringAsPackage pkgName script = do |