From 7413b229091255151a6bd2c50308dd0fd67c3036 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 6 Nov 2012 14:49:53 +0100
Subject: [PATCH] Move and rename BasicTypes.annotateIOError
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 htools/Ganeti/BasicTypes.hs | 7 -------
 htools/Ganeti/Daemon.hs     | 8 +++++++-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/htools/Ganeti/BasicTypes.hs b/htools/Ganeti/BasicTypes.hs
index 149540fdb..f37a52335 100644
--- a/htools/Ganeti/BasicTypes.hs
+++ b/htools/Ganeti/BasicTypes.hs
@@ -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.
diff --git a/htools/Ganeti/Daemon.hs b/htools/Ganeti/Daemon.hs
index 0ac861a07..51f08059a 100644
--- a/htools/Ganeti/Daemon.hs
+++ b/htools/Ganeti/Daemon.hs
@@ -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.
 --
-- 
GitLab