Skip to content
Snippets Groups Projects
Commit 7413b229 authored by Iustin Pop's avatar Iustin Pop
Browse files

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
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,6 @@ module Ganeti.BasicTypes ...@@ -31,7 +31,6 @@ module Ganeti.BasicTypes
, isBad , isBad
, eitherToResult , eitherToResult
, annotateResult , annotateResult
, annotateIOError
, select , select
, LookupResult(..) , LookupResult(..)
, MatchPriority(..) , MatchPriority(..)
...@@ -133,12 +132,6 @@ annotateResult :: String -> Result a -> Result a ...@@ -133,12 +132,6 @@ annotateResult :: String -> Result a -> Result a
annotateResult owner (Bad s) = Bad $ owner ++ ": " ++ s annotateResult owner (Bad s) = Bad $ owner ++ ": " ++ s
annotateResult _ v = v 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 -- * Misc functionality
-- | Return the first result with a True condition, or the default otherwise. -- | Return the first result with a True condition, or the default otherwise.
......
...@@ -188,6 +188,12 @@ genericOpts = [ oShowHelp ...@@ -188,6 +188,12 @@ genericOpts = [ oShowHelp
, oShowComp , 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'. -- | Small wrapper over getArgs and 'parseOpts'.
parseArgs :: String -> [OptType] -> IO (DaemonOptions, [String]) parseArgs :: String -> [OptType] -> IO (DaemonOptions, [String])
parseArgs cmd options = do parseArgs cmd options = do
...@@ -290,7 +296,7 @@ parseAddress opts defport = do ...@@ -290,7 +296,7 @@ parseAddress opts defport = do
Nothing -> return (def_family >>= defaultBindAddr port) Nothing -> return (def_family >>= defaultBindAddr port)
Just saddr -> Control.Exception.catch Just saddr -> Control.Exception.catch
(resolveAddr port saddr) (resolveAddr port saddr)
(annotateIOError $ "Invalid address " ++ saddr) (ioErrorToResult $ "Invalid address " ++ saddr)
-- | Run an I/O action as a daemon. -- | Run an I/O action as a daemon.
-- --
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment