Commit 7413b229 authored by Iustin Pop's avatar Iustin Pop

Move and rename BasicTypes.annotateIOError

It turns out that annotateIOError already exists in the standard
library, with a different purpose (this made me waste 10 minutes
trying to understand why the types were wrong…). Let's move this out
of BasicTypes, since it's used only in Daemon.hs, and also rename it.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent b9097468
......@@ -31,7 +31,6 @@ module Ganeti.BasicTypes
, isBad
, eitherToResult
, annotateResult
, annotateIOError
, select
, LookupResult(..)
, MatchPriority(..)
......@@ -133,12 +132,6 @@ annotateResult :: String -> Result a -> Result a
annotateResult owner (Bad s) = Bad $ owner ++ ": " ++ s
annotateResult _ v = v
-- | Annotates and transforms IOErrors into a Result type. This can be
-- used in the error handler argument to 'catch', for example.
annotateIOError :: String -> IOError -> IO (Result a)
annotateIOError description exc =
return . Bad $ description ++ ": " ++ show exc
-- * Misc functionality
-- | Return the first result with a True condition, or the default otherwise.
......
......@@ -188,6 +188,12 @@ genericOpts = [ oShowHelp
, oShowComp
]
-- | Annotates and transforms IOErrors into a Result type. This can be
-- used in the error handler argument to 'catch', for example.
ioErrorToResult :: String -> IOError -> IO (Result a)
ioErrorToResult description exc =
return . Bad $ description ++ ": " ++ show exc
-- | Small wrapper over getArgs and 'parseOpts'.
parseArgs :: String -> [OptType] -> IO (DaemonOptions, [String])
parseArgs cmd options = do
......@@ -290,7 +296,7 @@ parseAddress opts defport = do
Nothing -> return (def_family >>= defaultBindAddr port)
Just saddr -> Control.Exception.catch
(resolveAddr port saddr)
(annotateIOError $ "Invalid address " ++ saddr)
(ioErrorToResult $ "Invalid address " ++ saddr)
-- | Run an I/O action as a daemon.
--
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment