Revision 5badb3e7 src/Ganeti/Utils.hs

b/src/Ganeti/Utils.hs
61 61
  , setOwnerAndGroupFromNames
62 62
  , formatOrdinal
63 63
  , atomicWriteFile
64
  , tryAndLogIOError
64 65
  ) where
65 66

  
67
import Control.Exception (try)
66 68
import Data.Char (toUpper, isAlphaNum, isDigit, isSpace)
67 69
import Data.Function (on)
68 70
import Data.List
......
268 270
  return defVal
269 271
logWarningIfBad _ _ (Ok v) = return v
270 272

  
273
-- | Try an IO interaction, log errors and unfold as a 'Result'.
274
tryAndLogIOError :: IO a -> String -> (a -> Result b) -> IO (Result b)
275
tryAndLogIOError io msg okfn =
276
 try io >>= either
277
   (\ e -> do
278
       let combinedmsg = msg ++ ": " ++ show (e :: IOError)
279
       logError combinedmsg
280
       return . Bad $ combinedmsg)
281
   (return . okfn)
282

  
271 283
-- | Print a warning, but do not exit.
272 284
warn :: String -> IO ()
273 285
warn = hPutStrLn stderr . (++) "Warning: "

Also available in: Unified diff