Use catch from Control.Exception to avoid warnings.
This commit is contained in:
parent
e6c76525b2
commit
308436996e
6 changed files with 28 additions and 16 deletions
|
@ -11,6 +11,7 @@ import System.Directory (getModificationTime)
|
|||
import System.IO.Error (isDoesNotExistError)
|
||||
import System.Time (ClockTime(..))
|
||||
import Data.Maybe (catMaybes)
|
||||
import qualified Control.Exception as E
|
||||
|
||||
main = do
|
||||
rmContents <- liftM toString $ B.readFile "README"
|
||||
|
@ -47,7 +48,7 @@ writeManPage page templ doc = do
|
|||
-- | Returns a list of 'dependencies' that have been modified after 'file'.
|
||||
modifiedDependencies :: FilePath -> [FilePath] -> IO [FilePath]
|
||||
modifiedDependencies file dependencies = do
|
||||
fileModTime <- catch (getModificationTime file) $
|
||||
fileModTime <- E.catch (getModificationTime file) $
|
||||
\e -> if isDoesNotExistError e
|
||||
then return (TOD 0 0) -- the minimum ClockTime
|
||||
else ioError e
|
||||
|
|
3
Setup.hs
3
Setup.hs
|
@ -9,7 +9,8 @@ import Distribution.Verbosity ( Verbosity, silent )
|
|||
import Distribution.Simple.GHC (ghcPackageDbOptions)
|
||||
import Distribution.Simple.InstallDirs (mandir, bindir, CopyDest (NoCopyDest))
|
||||
import Distribution.Simple.Utils (installOrdinaryFiles)
|
||||
import Control.Exception ( bracket_ )
|
||||
import Prelude hiding (catch)
|
||||
import Control.Exception ( bracket_, catch )
|
||||
import Control.Monad ( unless )
|
||||
import System.Process ( rawSystem, runCommand, waitForProcess )
|
||||
import System.FilePath ( (</>) )
|
||||
|
|
|
@ -46,6 +46,7 @@ import Data.Monoid
|
|||
import System.FilePath (replaceExtension)
|
||||
import Data.List (intercalate)
|
||||
import qualified Data.Map as M
|
||||
import qualified Control.Exception as E
|
||||
|
||||
-- | Parse LaTeX from string and return 'Pandoc' document.
|
||||
readLaTeX :: ParserState -- ^ Parser state, including options for parser
|
||||
|
@ -670,8 +671,9 @@ handleIncludes :: String -> IO String
|
|||
handleIncludes [] = return []
|
||||
handleIncludes ('\\':xs) =
|
||||
case runParser include defaultParserState "input" ('\\':xs) of
|
||||
Right (fs, rest) -> do let getfile f = catch (UTF8.readFile f)
|
||||
(\_ -> return "")
|
||||
Right (fs, rest) -> do let getfile f = E.catch (UTF8.readFile f)
|
||||
(\e -> let _ = (e :: E.SomeException)
|
||||
in return "")
|
||||
yss <- mapM getfile fs
|
||||
(intercalate "\n" yss ++) `fmap`
|
||||
handleIncludes rest
|
||||
|
|
|
@ -47,6 +47,7 @@ import Control.Monad (liftM)
|
|||
import Network.URI ( unEscapeString )
|
||||
import Text.Pandoc.XML
|
||||
import Text.Pandoc.Pretty
|
||||
import qualified Control.Exception as E
|
||||
|
||||
-- | Produce an ODT file from a Pandoc document.
|
||||
writeODT :: WriterOptions -- ^ Writer options
|
||||
|
@ -109,9 +110,9 @@ transformPic sourceDir entriesRef (Image lab (src,tit)) = do
|
|||
Nothing -> tit
|
||||
entries <- readIORef entriesRef
|
||||
let newsrc = "Pictures/" ++ show (length entries) ++ takeExtension src'
|
||||
catch (readEntry [] (sourceDir </> src') >>= \entry ->
|
||||
modifyIORef entriesRef (entry{ eRelativePath = newsrc } :) >>
|
||||
return (Image lab (newsrc, tit')))
|
||||
(\_ -> return (Emph lab))
|
||||
E.catch (readEntry [] (sourceDir </> src') >>= \entry ->
|
||||
modifyIORef entriesRef (entry{ eRelativePath = newsrc } :) >>
|
||||
return (Image lab (newsrc, tit')))
|
||||
(\e -> let _ = (e :: E.SomeException) in return (Emph lab))
|
||||
transformPic _ _ x = return x
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ import System.FilePath ( takeExtension )
|
|||
import qualified Data.ByteString as B
|
||||
import Text.Printf ( printf )
|
||||
import Network.URI ( isAbsoluteURI, unEscapeString )
|
||||
import qualified Control.Exception as E
|
||||
|
||||
-- | Convert Image inlines into a raw RTF embedded image, read from a file.
|
||||
-- If file not found or filetype not jpeg or png, leave the inline unchanged.
|
||||
|
@ -47,7 +48,8 @@ rtfEmbedImage x@(Image _ (src,_)) = do
|
|||
if ext `elem` [".jpg",".jpeg",".png"] && not (isAbsoluteURI src)
|
||||
then do
|
||||
let src' = unEscapeString src
|
||||
imgdata <- catch (B.readFile src') (\_ -> return B.empty)
|
||||
imgdata <- E.catch (B.readFile src')
|
||||
(\e -> let _ = (e :: E.SomeException) in return B.empty)
|
||||
let bytes = map (printf "%02x") $ B.unpack imgdata
|
||||
let filetype = case ext of
|
||||
".jpg" -> "\\jpegblip"
|
||||
|
|
|
@ -48,6 +48,7 @@ import Data.List ( intercalate, isSuffixOf, isPrefixOf )
|
|||
import System.Directory ( getAppUserDataDirectory, doesFileExist, findExecutable )
|
||||
import System.IO ( stdout )
|
||||
import System.IO.Error ( isDoesNotExistError )
|
||||
import qualified Control.Exception as E
|
||||
import Control.Exception.Extensible ( throwIO )
|
||||
import qualified Text.Pandoc.UTF8 as UTF8
|
||||
import qualified Text.CSL as CSL
|
||||
|
@ -840,9 +841,10 @@ main = do
|
|||
let sources = if ignoreArgs then [] else args
|
||||
|
||||
datadir <- case mbDataDir of
|
||||
Nothing -> catch
|
||||
Nothing -> E.catch
|
||||
(liftM Just $ getAppUserDataDirectory "pandoc")
|
||||
(const $ return Nothing)
|
||||
(\e -> let _ = (e :: E.SomeException)
|
||||
in return Nothing)
|
||||
Just _ -> return mbDataDir
|
||||
|
||||
-- assign reader and writer based on options and filenames
|
||||
|
@ -893,12 +895,13 @@ main = do
|
|||
let tp' = case takeExtension tp of
|
||||
"" -> tp <.> format
|
||||
_ -> tp
|
||||
catch (UTF8.readFile tp')
|
||||
E.catch (UTF8.readFile tp')
|
||||
(\e -> if isDoesNotExistError e
|
||||
then catch
|
||||
then E.catch
|
||||
(readDataFile datadir $
|
||||
"templates" </> tp')
|
||||
(\_ -> throwIO e)
|
||||
(\e' -> let _ = (e' :: E.SomeException)
|
||||
in throwIO e')
|
||||
else throwIO e)
|
||||
|
||||
variables' <- case mathMethod of
|
||||
|
@ -922,8 +925,10 @@ main = do
|
|||
-- that we can do lookups with regular string equality
|
||||
let unescapeRefId ref = ref{ refId = fromEntities (refId ref) }
|
||||
|
||||
refs <- mapM (\f -> catch (CSL.readBiblioFile f) $ \e ->
|
||||
err 23 $ "Error reading bibliography `" ++ f ++ "'" ++ "\n" ++ show e)
|
||||
refs <- mapM (\f -> E.catch (CSL.readBiblioFile f)
|
||||
(\e -> let _ = (e :: E.SomeException)
|
||||
in err 23 $ "Error reading bibliography `" ++ f ++
|
||||
"'" ++ "\n" ++ show e))
|
||||
reffiles >>=
|
||||
return . map unescapeRefId . concat
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue