If we do not catch these errors, any malformed entry in a media bag could cause the loss of a whole document output. An example of malformed entry is an entry with an empty file path.
This commit is contained in:
parent
8cd3f19dc5
commit
59f0c1d83b
2 changed files with 15 additions and 1 deletions
|
@ -477,6 +477,14 @@ liftIOError f u = do
|
||||||
Left e -> throwError $ PandocIOError u e
|
Left e -> throwError $ PandocIOError u e
|
||||||
Right r -> return r
|
Right r -> return r
|
||||||
|
|
||||||
|
-- | Show potential IO errors to the user continuing execution anyway
|
||||||
|
logIOError :: IO () -> PandocIO ()
|
||||||
|
logIOError f = do
|
||||||
|
res <- liftIO $ tryIOError f
|
||||||
|
case res of
|
||||||
|
Left e -> report $ IgnoredIOError (E.displayException e)
|
||||||
|
Right _ -> pure ()
|
||||||
|
|
||||||
instance PandocMonad PandocIO where
|
instance PandocMonad PandocIO where
|
||||||
lookupEnv = liftIO . IO.lookupEnv
|
lookupEnv = liftIO . IO.lookupEnv
|
||||||
getCurrentTime = liftIO IO.getCurrentTime
|
getCurrentTime = liftIO IO.getCurrentTime
|
||||||
|
@ -862,7 +870,7 @@ writeMedia dir mediabag subpath = do
|
||||||
Just (_, bs) -> do
|
Just (_, bs) -> do
|
||||||
report $ Extracting fullpath
|
report $ Extracting fullpath
|
||||||
liftIOError (createDirectoryIfMissing True) (takeDirectory fullpath)
|
liftIOError (createDirectoryIfMissing True) (takeDirectory fullpath)
|
||||||
liftIOError (\p -> BL.writeFile p bs) fullpath
|
logIOError $ BL.writeFile fullpath bs
|
||||||
|
|
||||||
adjustImagePath :: FilePath -> [FilePath] -> Inline -> Inline
|
adjustImagePath :: FilePath -> [FilePath] -> Inline -> Inline
|
||||||
adjustImagePath dir paths (Image attr lab (src, tit))
|
adjustImagePath dir paths (Image attr lab (src, tit))
|
||||||
|
|
|
@ -85,6 +85,7 @@ data LogMessage =
|
||||||
| InlineNotRendered Inline
|
| InlineNotRendered Inline
|
||||||
| BlockNotRendered Block
|
| BlockNotRendered Block
|
||||||
| DocxParserWarning String
|
| DocxParserWarning String
|
||||||
|
| IgnoredIOError String
|
||||||
| CouldNotFetchResource String String
|
| CouldNotFetchResource String String
|
||||||
| CouldNotDetermineImageSize String String
|
| CouldNotDetermineImageSize String String
|
||||||
| CouldNotConvertImage String String
|
| CouldNotConvertImage String String
|
||||||
|
@ -175,6 +176,8 @@ instance ToJSON LogMessage where
|
||||||
["contents" .= toJSON bl]
|
["contents" .= toJSON bl]
|
||||||
DocxParserWarning s ->
|
DocxParserWarning s ->
|
||||||
["contents" .= Text.pack s]
|
["contents" .= Text.pack s]
|
||||||
|
IgnoredIOError s ->
|
||||||
|
["contents" .= Text.pack s]
|
||||||
CouldNotFetchResource fp s ->
|
CouldNotFetchResource fp s ->
|
||||||
["path" .= Text.pack fp,
|
["path" .= Text.pack fp,
|
||||||
"message" .= Text.pack s]
|
"message" .= Text.pack s]
|
||||||
|
@ -265,6 +268,8 @@ showLogMessage msg =
|
||||||
"Not rendering " ++ show bl
|
"Not rendering " ++ show bl
|
||||||
DocxParserWarning s ->
|
DocxParserWarning s ->
|
||||||
"Docx parser warning: " ++ s
|
"Docx parser warning: " ++ s
|
||||||
|
IgnoredIOError s ->
|
||||||
|
"IO Error (ignored): " ++ s
|
||||||
CouldNotFetchResource fp s ->
|
CouldNotFetchResource fp s ->
|
||||||
"Could not fetch resource '" ++ fp ++ "'" ++
|
"Could not fetch resource '" ++ fp ++ "'" ++
|
||||||
if null s then "" else ": " ++ s
|
if null s then "" else ": " ++ s
|
||||||
|
@ -332,6 +337,7 @@ messageVerbosity msg =
|
||||||
InlineNotRendered{} -> INFO
|
InlineNotRendered{} -> INFO
|
||||||
BlockNotRendered{} -> INFO
|
BlockNotRendered{} -> INFO
|
||||||
DocxParserWarning{} -> INFO
|
DocxParserWarning{} -> INFO
|
||||||
|
IgnoredIOError{} -> WARNING
|
||||||
CouldNotFetchResource{} -> WARNING
|
CouldNotFetchResource{} -> WARNING
|
||||||
CouldNotDetermineImageSize{} -> WARNING
|
CouldNotDetermineImageSize{} -> WARNING
|
||||||
CouldNotConvertImage{} -> WARNING
|
CouldNotConvertImage{} -> WARNING
|
||||||
|
|
Loading…
Add table
Reference in a new issue