git.iko.soy/typeable/pandoc
on master help sign in
Added PandocResourceNotFound error.

Use this instead of PandocIOError when a resource is not found in path. This improves the error message in this case, see #3629.

commitcd2551c16c1da0404b8de182f17160aebb69219d authorJohn MacFarlane <jgm@berkeley.edu> dateTue 2 May 2017, 16:00 (10 years ago) parent022d58e
6 files changed+14−29
src/Text/Pandoc/Class.hs+4−8 src/Text/Pandoc/Error.hs+3 src/Text/Pandoc/Writers/Docx.hs+4−7 src/Text/Pandoc/Writers/ICML.hs+1−5 src/Text/Pandoc/Writers/ODT.hs+1−5 src/Text/Pandoc/Writers/RTF.hs+1−4
src/Text/Pandoc/Class.hs+4−8
@@ -330,8 +330,7 @@ downloadOrRead sourceURL s = do
330330 convertSlash x = x
331331
332332withPaths :: PandocMonad m => [FilePath] -> (FilePath -> m a) -> FilePath -> m a
333−withPaths [] _ fp = throwError $ PandocIOError fp
334− (userError "file not found in resource path")
333+withPaths [] _ fp = throwError $ PandocResourceNotFound fp
335334withPaths (p:ps) action fp =
336335 catchError (action (p </> fp))
337336 (\_ -> withPaths ps action fp)
@@ -433,20 +432,17 @@ instance PandocMonad PandocPure where
433432 modifyPureState $ \st -> st { stUniqStore = us }
434433 return u
435434 _ -> M.fail "uniq store ran out of elements"
436− openURL u = throwError $ PandocIOError u $
437− userError "Cannot open URL in PandocPure"
435+ openURL u = throwError $ PandocResourceNotFound u
438436 readFileLazy fp = do
439437 fps <- getsPureState stFiles
440438 case infoFileContents <$> getFileInfo fp fps of
441439 Just bs -> return (BL.fromStrict bs)
442− Nothing -> throwError $ PandocIOError fp
443− (userError "File not found in PureState")
440+ Nothing -> throwError $ PandocResourceNotFound fp
444441 readFileStrict fp = do
445442 fps <- getsPureState stFiles
446443 case infoFileContents <$> getFileInfo fp fps of
447444 Just bs -> return bs
448− Nothing -> throwError $ PandocIOError fp
449− (userError "File not found in PureState")
445+ Nothing -> throwError $ PandocResourceNotFound fp
450446 readDataFile Nothing "reference.docx" = do
451447 (B.concat . BL.toChunks . fromArchive) <$> getsPureState stReferenceDocx
452448 readDataFile Nothing "reference.odt" = do
src/Text/Pandoc/Error.hs+3
@@ -58,6 +58,7 @@ data PandocError = PandocIOError String IOError
5858 | PandocPDFError String
5959 | PandocFilterError String String
6060 | PandocCouldNotFindDataFileError String
61+ | PandocResourceNotFound String
6162 | PandocAppError String
6263 deriving (Show, Typeable, Generic)
6364
@@ -94,6 +95,8 @@ handleError (Left e) =
9495 filtername ++ ":\n" ++ msg
9596 PandocCouldNotFindDataFileError fn -> err 97 $
9697 "Could not find data file " ++ fn
98+ PandocResourceNotFound fn -> err 99 $
99+ "File " ++ fn ++ " not found in resource path"
97100 PandocAppError s -> err 1 s
98101
99102err :: Int -> String -> IO a
src/Text/Pandoc/Writers/Docx.hs+4−7
@@ -55,7 +55,6 @@ import Text.Pandoc.Class (PandocMonad, report)
5555import qualified Text.Pandoc.Class as P
5656import Text.Pandoc.Compat.Time
5757import Text.Pandoc.Definition
58−import Text.Pandoc.Error
5958import Text.Pandoc.Generic
6059import Text.Pandoc.Highlighting (highlight)
6160import Text.Pandoc.ImageSize
@@ -1303,12 +1302,10 @@ inlineToOpenXML' opts (Image attr alt (src, title)) = do
13031302 M.insert src (ident, imgpath, mbMimeType, imgElt, img)
13041303 $ stImages st }
13051304 return [imgElt])
1306− (\e -> do case e of
1307− PandocIOError _ e' ->
1308− report $ CouldNotFetchResource src (show e')
1309− e' -> report $ CouldNotFetchResource src (show e')
1310− -- emit alt text
1311− inlinesToOpenXML opts alt)
1305+ (\e -> do
1306+ report $ CouldNotFetchResource src (show e)
1307+ -- emit alt text
1308+ inlinesToOpenXML opts alt)
13121309
13131310br :: Element
13141311br = breakElement "textWrapping"
src/Text/Pandoc/Writers/ICML.hs+1−5
@@ -25,7 +25,6 @@ import Network.URI (isURI)
2525import Text.Pandoc.Class (PandocMonad, report)
2626import qualified Text.Pandoc.Class as P
2727import Text.Pandoc.Definition
28−import Text.Pandoc.Error (PandocError (..))
2928import Text.Pandoc.ImageSize
3029import Text.Pandoc.Logging
3130import Text.Pandoc.Options
@@ -550,10 +549,7 @@ imageICML opts style attr (src, _) = do
550549 report $ CouldNotDetermineImageSize src msg
551550 return def)
552551 (\e -> do
553− case e of
554− PandocIOError _ e' ->
555− report $ CouldNotFetchResource src (show e')
556− e' -> report $ CouldNotFetchResource src (show e')
552+ report $ CouldNotFetchResource src (show e)
557553 return def)
558554 let (ow, oh) = sizeInPoints imgS
559555 (imgWidth, imgHeight) = desiredSizeInPoints opts attr imgS
src/Text/Pandoc/Writers/ODT.hs+1−5
@@ -39,7 +39,6 @@ import System.FilePath (takeDirectory, takeExtension, (<.>))
3939import Text.Pandoc.Class (PandocMonad, report)
4040import qualified Text.Pandoc.Class as P
4141import Text.Pandoc.Definition
42−import Text.Pandoc.Error (PandocError (..))
4342import Text.Pandoc.ImageSize
4443import Text.Pandoc.Logging
4544import Text.Pandoc.MIME (extensionFromMimeType, getMimeType)
@@ -178,10 +177,7 @@ transformPicMath opts (Image attr@(id', cls, _) lab (src,t)) = catchError
178177 modify $ \st -> st{ stEntries = entry : entries }
179178 return $ Image newattr lab (newsrc, t))
180179 (\e -> do
181− case e of
182− PandocIOError _ e' ->
183− report $ CouldNotFetchResource src (show e')
184− e' -> report $ CouldNotFetchResource src (show e')
180+ report $ CouldNotFetchResource src (show e)
185181 return $ Emph lab)
186182
187183transformPicMath _ (Math t math) = do
src/Text/Pandoc/Writers/RTF.hs+1−4
@@ -92,10 +92,7 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = catchError
9292 report $ CouldNotDetermineMimeType src
9393 return x)
9494 (\e -> do
95− case e of
96− PandocIOError _ e' ->
97− report $ CouldNotFetchResource src (show e')
98− e' -> report $ CouldNotFetchResource src (show e')
95+ report $ CouldNotFetchResource src (show e)
9996 return x)
10097rtfEmbedImage _ x = return x
10198