From 175cc3371f0b27c68ae0e5f70f7e4383b0d9d5a4 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Wed, 15 Jul 2009 19:22:44 +0200 Subject: [PATCH] CLI: Handle error better This patch adds an error handler for any exceptions that are raised during the external data load phase. This can be improved further, but it's a good start. --- Ganeti/HTools/CLI.hs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Ganeti/HTools/CLI.hs b/Ganeti/HTools/CLI.hs index c859784a7..78217da37 100644 --- a/Ganeti/HTools/CLI.hs +++ b/Ganeti/HTools/CLI.hs @@ -60,6 +60,7 @@ module Ganeti.HTools.CLI , oShowHelp ) where +import Control.Exception import Data.Maybe (isJust, fromJust, fromMaybe) import qualified Data.Version import Monad @@ -312,6 +313,12 @@ shTemplate = \ fi\n\ \}\n\n" +-- | Error beautifier +wrapIO :: IO (Result a) -> IO (Result a) +wrapIO act = + handle (\e -> return $ Bad $ show e) + act + -- | External tool data loader from a variety of sources. loadExternalData :: Options -> IO (Node.List, Instance.List, String) @@ -335,9 +342,9 @@ loadExternalData opts = do input_data <- case () of - _ | mhost /= "" -> Rapi.loadData mhost - | isJust lsock -> Luxi.loadData $ fromJust lsock - | otherwise -> Text.loadData nodef instf + _ | setRapi -> wrapIO $ Rapi.loadData mhost + | setLuxi -> wrapIO $ Luxi.loadData $ fromJust lsock + | otherwise -> wrapIO $ Text.loadData nodef instf let ldresult = input_data >>= Loader.mergeData (loaded_nl, il, csf) <- -- GitLab