diff --git a/htools/Ganeti/HTools/ExtLoader.hs b/htools/Ganeti/HTools/ExtLoader.hs index 2defadecf72d5e222a32621f03ddee48da95d52e..bd258f5f3cb63104bf01874db4a9c0ae538796f8 100644 --- a/htools/Ganeti/HTools/ExtLoader.hs +++ b/htools/Ganeti/HTools/ExtLoader.hs @@ -34,7 +34,9 @@ module Ganeti.HTools.ExtLoader ) where import Control.Monad +import Control.Exception import Data.Maybe (isJust, fromJust) +import Prelude hiding (catch) import System.FilePath import System.IO import Text.Printf (hPrintf) @@ -53,7 +55,7 @@ import Ganeti.HTools.Utils (sepSplit, tryRead, exitIfBad, exitWhen) -- | Error beautifier. wrapIO :: IO (Result a) -> IO (Result a) -wrapIO = flip catch (return . Bad . show) +wrapIO = flip catch (\e -> return . Bad . show $ (e::IOException)) -- | Parses a user-supplied utilisation string. parseUtilisation :: String -> Result (String, DynUtil) diff --git a/htools/Ganeti/HTools/Rapi.hs b/htools/Ganeti/HTools/Rapi.hs index d52abab1c002121839131647bc93eb430268663a..710bfbb6f6ca3a416051dccd19a5c733b65be9be 100644 --- a/htools/Ganeti/HTools/Rapi.hs +++ b/htools/Ganeti/HTools/Rapi.hs @@ -30,6 +30,7 @@ module Ganeti.HTools.Rapi , parseData ) where +import Control.Exception import Data.List (isPrefixOf) import Data.Maybe (fromMaybe) #ifndef NO_CURL @@ -37,6 +38,7 @@ import Network.Curl import Network.Curl.Types () #endif import Control.Monad +import Prelude hiding (catch) import Text.JSON (JSObject, fromJSObject, decodeStrict) import Text.JSON.Types (JSValue(..)) import Text.Printf (printf) @@ -83,7 +85,8 @@ getUrl url = do -- | Helper to convert I/O errors in 'Bad' values. ioErrToResult :: IO a -> IO (Result a) ioErrToResult ioaction = - catch (ioaction >>= return . Ok) (return . Bad . show) + catch (ioaction >>= return . Ok) + (\e -> return . Bad . show $ (e::IOException)) -- | Append the default port if not passed in. formatHost :: String -> String diff --git a/htools/htools.hs b/htools/htools.hs index f35c18cdf9238d421131978850a4e756ae0e0fe3..2e847d7f2fc97655d349a78dfe950b8d237a200e 100644 --- a/htools/htools.hs +++ b/htools/htools.hs @@ -25,10 +25,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Main (main) where +import Control.Exception +import Control.Monad (guard) import Data.Char (toLower) +import Prelude hiding (catch) import System.Environment import System.Exit import System.IO +import System.IO.Error (isDoesNotExistError) import Ganeti.HTools.Utils import Ganeti.HTools.CLI (parseOpts) @@ -47,7 +51,8 @@ usage name = do main :: IO () main = do - binary <- getEnv "HTOOLS" `catch` const getProgName + binary <- catchJust (guard . isDoesNotExistError) + (getEnv "HTOOLS") (const getProgName) let name = map toLower binary boolnames = map (\(x, y) -> (x == name, Just y)) personalities case select Nothing boolnames of