git.iko.soy/typeable/pandoc
on master help sign in
Setup.hs: better version detection in older hsb2hs.

If it returns an error with input `--version`, recover gracefully.

commite042f697a4557b21789cb7404745746aea2535b4 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 6 Jul 2015, 13:38 (11 years ago) parent48cd774
1 file changed+11−7
Setup.hs+11−7
Setup.hs+11−7
@@ -32,6 +32,7 @@ import Data.Version
3232import System.Process (readProcess)
3333import Text.ParserCombinators.ReadP (readP_to_S, skipSpaces, eof)
3434import Control.Monad (when)
35+import qualified Control.Exception as E
3536
3637main :: IO ()
3738main = defaultMainWithHooks $ simpleUserHooks {
@@ -44,13 +45,16 @@ main = defaultMainWithHooks $ simpleUserHooks {
4445
4546findHsb2hsVersion :: Verbosity -> FilePath -> IO (Maybe Version)
4647findHsb2hsVersion verb fp = do
47− outp <- readProcess fp ["--version"] ""
48− case readP_to_S (do v <- parseVersion
49− skipSpaces
50− eof
51− return v) outp of
52− ((v,""):_) -> return (Just v)
53− _ -> return Nothing
48+ let handleExitFailure :: IOError -> IO (Maybe Version)
49+ handleExitFailure _ = return Nothing
50+ E.handle handleExitFailure $ do
51+ outp <- readProcess fp ["--version"] ""
52+ case readP_to_S (do v <- parseVersion
53+ skipSpaces
54+ eof
55+ return v) outp of
56+ ((v,""):_) -> return (Just v)
57+ _ -> return Nothing
5458
5559ppBlobSuffixHandler :: PPSuffixHandler
5660ppBlobSuffixHandler = ("hsb", \_ lbi ->