) 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)
-- | 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)
, parseData
) where
+import Control.Exception
import Data.List (isPrefixOf)
import Data.Maybe (fromMaybe)
#ifndef NO_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)
-- | 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
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)
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