git.iko.soy/typeable/pandoc
on master help sign in
Added PandocResourceNotFound error.
cd2551cJohn MacFarlane
src/Text/Pandoc/Class.hs+4−8
@@ -330,8 +330,7 @@ downloadOrRead sourceURL s = do
330 convertSlash x = x
330 convertSlash x = x
331
331
332withPaths :: PandocMonad m => [FilePath] -> (FilePath -> m a) -> FilePath -> m a
332withPaths :: PandocMonad m => [FilePath] -> (FilePath -> m a) -> FilePath -> m a
333−withPaths [] _ fp = throwError $ PandocIOError fp
333+withPaths [] _ fp = throwError $ PandocResourceNotFound fp
334− (userError "file not found in resource path")
335withPaths (p:ps) action fp =
334withPaths (p:ps) action fp =
336 catchError (action (p </> fp))
335 catchError (action (p </> fp))
337 (\_ -> withPaths ps action fp)
336 (\_ -> withPaths ps action fp)
@@ -433,20 +432,17 @@ instance PandocMonad PandocPure where
433 modifyPureState $ \st -> st { stUniqStore = us }
432 modifyPureState $ \st -> st { stUniqStore = us }
434 return u
433 return u
435 _ -> M.fail "uniq store ran out of elements"
434 _ -> M.fail "uniq store ran out of elements"
436− openURL u = throwError $ PandocIOError u $
435+ openURL u = throwError $ PandocResourceNotFound u
437− userError "Cannot open URL in PandocPure"
438 readFileLazy fp = do
436 readFileLazy fp = do
439 fps <- getsPureState stFiles
437 fps <- getsPureState stFiles
440 case infoFileContents <$> getFileInfo fp fps of
438 case infoFileContents <$> getFileInfo fp fps of
441 Just bs -> return (BL.fromStrict bs)
439 Just bs -> return (BL.fromStrict bs)
442− Nothing -> throwError $ PandocIOError fp
440+ Nothing -> throwError $ PandocResourceNotFound fp
443− (userError "File not found in PureState")
444 readFileStrict fp = do
441 readFileStrict fp = do
445 fps <- getsPureState stFiles
442 fps <- getsPureState stFiles
446 case infoFileContents <$> getFileInfo fp fps of
443 case infoFileContents <$> getFileInfo fp fps of
447 Just bs -> return bs
444 Just bs -> return bs
448− Nothing -> throwError $ PandocIOError fp
445+ Nothing -> throwError $ PandocResourceNotFound fp
449− (userError "File not found in PureState")
450 readDataFile Nothing "reference.docx" = do
446 readDataFile Nothing "reference.docx" = do
451 (B.concat . BL.toChunks . fromArchive) <$> getsPureState stReferenceDocx
447 (B.concat . BL.toChunks . fromArchive) <$> getsPureState stReferenceDocx
452 readDataFile Nothing "reference.odt" = do
448 readDataFile Nothing "reference.odt" = do
src/Text/Pandoc/Error.hs+3
@@ -58,6 +58,7 @@ data PandocError = PandocIOError String IOError
58 | PandocPDFError String
58 | PandocPDFError String
59 | PandocFilterError String String
59 | PandocFilterError String String
60 | PandocCouldNotFindDataFileError String
60 | PandocCouldNotFindDataFileError String
61+ | PandocResourceNotFound String
61 | PandocAppError String
62 | PandocAppError String
62 deriving (Show, Typeable, Generic)
63 deriving (Show, Typeable, Generic)
63
64
@@ -94,6 +95,8 @@ handleError (Left e) =
94 filtername ++ ":\n" ++ msg
95 filtername ++ ":\n" ++ msg
95 PandocCouldNotFindDataFileError fn -> err 97 $
96 PandocCouldNotFindDataFileError fn -> err 97 $
96 "Could not find data file " ++ fn
97 "Could not find data file " ++ fn
98+ PandocResourceNotFound fn -> err 99 $
99+ "File " ++ fn ++ " not found in resource path"
97 PandocAppError s -> err 1 s
100 PandocAppError s -> err 1 s
98
101
99err :: Int -> String -> IO a
102err :: Int -> String -> IO a
src/Text/Pandoc/Writers/Docx.hs+4−7
@@ -55,7 +55,6 @@ import Text.Pandoc.Class (PandocMonad, report)
55import qualified Text.Pandoc.Class as P
55import qualified Text.Pandoc.Class as P
56import Text.Pandoc.Compat.Time
56import Text.Pandoc.Compat.Time
57import Text.Pandoc.Definition
57import Text.Pandoc.Definition
58−import Text.Pandoc.Error
59import Text.Pandoc.Generic
58import Text.Pandoc.Generic
60import Text.Pandoc.Highlighting (highlight)
59import Text.Pandoc.Highlighting (highlight)
61import Text.Pandoc.ImageSize
60import Text.Pandoc.ImageSize
@@ -1303,12 +1302,10 @@ inlineToOpenXML' opts (Image attr alt (src, title)) = do
1303 M.insert src (ident, imgpath, mbMimeType, imgElt, img)
1302 M.insert src (ident, imgpath, mbMimeType, imgElt, img)
1304 $ stImages st }
1303 $ stImages st }
1305 return [imgElt])
1304 return [imgElt])
1306− (\e -> do case e of
1305+ (\e -> do
1307− PandocIOError _ e' ->
1308− report $ CouldNotFetchResource src (show e')
1306+ report $ CouldNotFetchResource src (show e)
1309− e' -> report $ CouldNotFetchResource src (show e')
1310− -- emit alt text
1307+ -- emit alt text
1311− inlinesToOpenXML opts alt)
1308+ inlinesToOpenXML opts alt)
1312
1309
1313br :: Element
1310br :: Element
1314br = breakElement "textWrapping"
1311br = breakElement "textWrapping"
src/Text/Pandoc/Writers/ICML.hs+1−5
@@ -25,7 +25,6 @@ import Network.URI (isURI)
25import Text.Pandoc.Class (PandocMonad, report)
25import Text.Pandoc.Class (PandocMonad, report)
26import qualified Text.Pandoc.Class as P
26import qualified Text.Pandoc.Class as P
27import Text.Pandoc.Definition
27import Text.Pandoc.Definition
28−import Text.Pandoc.Error (PandocError (..))
29import Text.Pandoc.ImageSize
28import Text.Pandoc.ImageSize
30import Text.Pandoc.Logging
29import Text.Pandoc.Logging
31import Text.Pandoc.Options
30import Text.Pandoc.Options
@@ -550,10 +549,7 @@ imageICML opts style attr (src, _) = do
550 report $ CouldNotDetermineImageSize src msg
549 report $ CouldNotDetermineImageSize src msg
551 return def)
550 return def)
552 (\e -> do
551 (\e -> do
553− case e of
554− PandocIOError _ e' ->
555− report $ CouldNotFetchResource src (show e')
552+ report $ CouldNotFetchResource src (show e)
556− e' -> report $ CouldNotFetchResource src (show e')
557 return def)
553 return def)
558 let (ow, oh) = sizeInPoints imgS
554 let (ow, oh) = sizeInPoints imgS
559 (imgWidth, imgHeight) = desiredSizeInPoints opts attr imgS
555 (imgWidth, imgHeight) = desiredSizeInPoints opts attr imgS
src/Text/Pandoc/Writers/ODT.hs+1−5
@@ -39,7 +39,6 @@ import System.FilePath (takeDirectory, takeExtension, (<.>))
39import Text.Pandoc.Class (PandocMonad, report)
39import Text.Pandoc.Class (PandocMonad, report)
40import qualified Text.Pandoc.Class as P
40import qualified Text.Pandoc.Class as P
41import Text.Pandoc.Definition
41import Text.Pandoc.Definition
42−import Text.Pandoc.Error (PandocError (..))
43import Text.Pandoc.ImageSize
42import Text.Pandoc.ImageSize
44import Text.Pandoc.Logging
43import Text.Pandoc.Logging
45import Text.Pandoc.MIME (extensionFromMimeType, getMimeType)
44import Text.Pandoc.MIME (extensionFromMimeType, getMimeType)
@@ -178,10 +177,7 @@ transformPicMath opts (Image attr@(id', cls, _) lab (src,t)) = catchError
178 modify $ \st -> st{ stEntries = entry : entries }
177 modify $ \st -> st{ stEntries = entry : entries }
179 return $ Image newattr lab (newsrc, t))
178 return $ Image newattr lab (newsrc, t))
180 (\e -> do
179 (\e -> do
181− case e of
182− PandocIOError _ e' ->
183− report $ CouldNotFetchResource src (show e')
180+ report $ CouldNotFetchResource src (show e)
184− e' -> report $ CouldNotFetchResource src (show e')
185 return $ Emph lab)
181 return $ Emph lab)
186
182
187transformPicMath _ (Math t math) = do
183transformPicMath _ (Math t math) = do
src/Text/Pandoc/Writers/RTF.hs+1−4
@@ -92,10 +92,7 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = catchError
92 report $ CouldNotDetermineMimeType src
92 report $ CouldNotDetermineMimeType src
93 return x)
93 return x)
94 (\e -> do
94 (\e -> do
95− case e of
96− PandocIOError _ e' ->
97− report $ CouldNotFetchResource src (show e')
95+ report $ CouldNotFetchResource src (show e)
98− e' -> report $ CouldNotFetchResource src (show e')
99 return x)
96 return x)
100rtfEmbedImage _ x = return x
97rtfEmbedImage _ x = return x
101
98