Revision 838393d1 src/Ganeti/Utils.hs
b/src/Ganeti/Utils.hs | ||
---|---|---|
43 | 43 |
, exitErr |
44 | 44 |
, exitWhen |
45 | 45 |
, exitUnless |
46 |
, logWarningIfBad |
|
46 | 47 |
, rStripSpace |
47 | 48 |
, newUUID |
48 | 49 |
, getCurrentTime |
... | ... | |
69 | 70 |
|
70 | 71 |
import Ganeti.BasicTypes |
71 | 72 |
import qualified Ganeti.Constants as C |
73 |
import Ganeti.Logging |
|
72 | 74 |
import Ganeti.Runtime |
73 | 75 |
import System.IO |
74 | 76 |
import System.Exit |
... | ... | |
252 | 254 |
exitUnless :: Bool -> String -> IO () |
253 | 255 |
exitUnless cond = exitWhen (not cond) |
254 | 256 |
|
257 |
-- | Unwraps a 'Result', logging a warning message and then returning a default |
|
258 |
-- value if it is a 'Bad' value, otherwise returning the actual contained value. |
|
259 |
logWarningIfBad :: String -> a -> Result a -> IO a |
|
260 |
logWarningIfBad msg defVal (Bad s) = do |
|
261 |
logWarning $ msg ++ ": " ++ s |
|
262 |
return defVal |
|
263 |
logWarningIfBad _ _ (Ok v) = return v |
|
264 |
|
|
255 | 265 |
-- | Print a warning, but do not exit. |
256 | 266 |
warn :: String -> IO () |
257 | 267 |
warn = hPutStrLn stderr . (++) "Warning: " |
Also available in: Unified diff