Revision 707cd3d7

b/htest/shelltests/htools-invalid.test
25 25
# extra arguments
26 26
./htest/hspace unexpected-argument
27 27
>>>2
28
Error: this program doesn't take any arguments.
28
Error: This program doesn't take any arguments.
29 29
>>>=1
30 30

  
31 31
./htest/hbal unexpected-argument
32 32
>>>2
33
Error: this program doesn't take any arguments.
33
Error: This program doesn't take any arguments.
34 34
>>>=1
35 35

  
36 36
./htest/hinfo unexpected-argument
37 37
>>>2
38
Error: this program doesn't take any arguments.
38
Error: This program doesn't take any arguments.
39 39
>>>=1
40 40

  
41 41
./htest/hcheck unexpected-argument
42 42
>>>2
43
Error: this program doesn't take any arguments.
43
Error: This program doesn't take any arguments.
44 44
>>>=1
b/htools/Ganeti/HTools/ExtLoader.hs
95 95
      exInsts = optExInst opts
96 96

  
97 97
  exitWhen (length allSet > 1) "Only one of the rapi, luxi, and data\
98
                               \ files options should be given"
98
                               \ files options should be given."
99 99

  
100 100
  util_contents <- maybe (return "") readFile (optDynuFile opts)
101 101
  util_data <- exitIfBad "can't parse utilisation data" .
b/htools/Ganeti/HTools/IAlloc.hs
36 36
import Control.Monad
37 37
import Text.JSON (JSObject, JSValue(JSArray),
38 38
                  makeObj, encodeStrict, decodeStrict, fromJSObject, showJSON)
39
import System.Exit
40
import System.IO
41 39

  
42 40
import Ganeti.BasicTypes
43 41
import qualified Ganeti.HTools.Cluster as Cluster
......
50 48
import Ganeti.HTools.Loader
51 49
import Ganeti.HTools.Types
52 50
import Ganeti.JSON
51
import Ganeti.Utils
53 52

  
54 53
{-# ANN module "HLint: ignore Eta reduce" #-}
55 54

  
......
385 384
                  "-" -> getContents
386 385
                  _   -> readFile fp
387 386
  case parseData input_data of
388
    Bad err -> do
389
      hPutStrLn stderr $ "Error: " ++ err
390
      exitWith $ ExitFailure 1
387
    Bad err -> exitErr err
391 388
    Ok (fix_msgs, rq) -> maybeShowWarnings fix_msgs >> return rq
392 389

  
393 390
-- | Main iallocator pipeline.
b/htools/Ganeti/HTools/Program/Hail.hs
32 32
import Control.Monad
33 33
import Data.Maybe (fromMaybe, isJust)
34 34
import System.IO
35
import System.Exit
36 35

  
37 36
import qualified Ganeti.HTools.Cluster as Cluster
38 37

  
......
41 40
import Ganeti.HTools.IAlloc
42 41
import Ganeti.HTools.Loader (Request(..), ClusterData(..))
43 42
import Ganeti.HTools.ExtLoader (maybeSaveData, loadExternalData)
43
import Ganeti.Utils
44 44

  
45 45
-- | Options list and functions.
46 46
options :: [OptType]
......
58 58

  
59 59
wrapReadRequest :: Options -> [String] -> IO Request
60 60
wrapReadRequest opts args = do
61
  when (null args) $ do
62
    hPutStrLn stderr "Error: this program needs an input file."
63
    exitWith $ ExitFailure 1
61
  when (null args) $ exitErr "This program needs an input file."
64 62

  
65 63
  r1 <- readRequest (head args)
66 64
  if isJust (optDataFile opts) ||  (not . null . optNodeSim) opts
b/htools/Ganeti/HTools/Program/Hbal.hs
273 273
    hPutStrLn stderr "Found multiple node groups:"
274 274
    mapM_ (hPutStrLn stderr . ("  " ++) . Group.name .
275 275
           flip Container.find gl . fst) ngroups
276
    hPutStrLn stderr "Aborting."
277
    exitWith $ ExitFailure 1
276
    exitErr "Aborting."
278 277

  
279 278
  case optGroup opts of
280 279
    Nothing -> do
......
286 285
        hPutStrLn stderr $ "Node group " ++ g ++
287 286
          " not found. Node group list is:"
288 287
        mapM_ (hPutStrLn stderr . ("  " ++) . Group.name ) (Container.elems gl)
289
        hPutStrLn stderr "Aborting."
290
        exitWith $ ExitFailure 1
288
        exitErr "Aborting."
291 289
      Just grp ->
292 290
          case lookup (Group.idx grp) ngroups of
293 291
            Nothing ->
......
350 348
-- | Main function.
351 349
main :: Options -> [String] -> IO ()
352 350
main opts args = do
353
  unless (null args) $ do
354
         hPutStrLn stderr "Error: this program doesn't take any arguments."
355
         exitWith $ ExitFailure 1
351
  unless (null args) $ exitErr "This program doesn't take any arguments."
356 352

  
357 353
  let verbose = optVerbose opts
358 354
      shownodes = optShowNodes opts
b/htools/Ganeti/HTools/Program/Hcheck.hs
32 32
import Control.Monad
33 33
import Data.List (transpose)
34 34
import System.Exit
35
import System.IO
36 35
import Text.Printf (printf)
37 36

  
38 37
import qualified Ganeti.HTools.Container as Container
......
48 47
import Ganeti.HTools.ExtLoader
49 48
import Ganeti.HTools.Loader
50 49
import Ganeti.HTools.Types
50
import Ganeti.Utils
51 51

  
52 52
-- | Options list and functions.
53 53
options :: [OptType]
......
295 295
-- | Main function.
296 296
main :: Options -> [String] -> IO ()
297 297
main opts args = do
298
  unless (null args) $ do
299
         hPutStrLn stderr "Error: this program doesn't take any arguments."
300
         exitWith $ ExitFailure 1
298
  unless (null args) $ exitErr "This program doesn't take any arguments."
301 299

  
302 300
  let verbose = optVerbose opts
303 301
      machineread = optMachineReadable opts
b/htools/Ganeti/HTools/Program/Hinfo.hs
31 31

  
32 32
import Control.Monad
33 33
import Data.List
34
import System.Exit
35 34
import System.IO
36 35

  
37 36
import Text.Printf (printf)
......
154 153
-- | Main function.
155 154
main :: Options -> [String] -> IO ()
156 155
main opts args = do
157
  unless (null args) $ do
158
         hPutStrLn stderr "Error: this program doesn't take any arguments."
159
         exitWith $ ExitFailure 1
156
  unless (null args) $ exitErr "This program doesn't take any arguments."
160 157

  
161 158
  let verbose = optVerbose opts
162 159
      shownodes = optShowNodes opts
b/htools/Ganeti/HTools/Program/Hspace.hs
387 387
-- | Main function.
388 388
main :: Options -> [String] -> IO ()
389 389
main opts args = do
390
  exitUnless (null args) "this program doesn't take any arguments"
390
  exitUnless (null args) "This program doesn't take any arguments."
391 391

  
392 392
  let verbose = optVerbose opts
393 393
      machine_r = optMachineReadable opts
b/htools/Ganeti/Utils.hs
213 213
-- | Unwraps a 'Result', exiting the program if it is a 'Bad' value,
214 214
-- otherwise returning the actual contained value.
215 215
exitIfBad :: String -> Result a -> IO a
216
exitIfBad msg (Bad s) = do
217
  hPutStrLn stderr $ "Error: " ++ msg ++ ": " ++ s
218
  exitWith (ExitFailure 1)
216
exitIfBad msg (Bad s) = exitErr (msg ++ ": " ++ s)
219 217
exitIfBad _ (Ok v) = return v
220 218

  
221 219
-- | Exits immediately with an error message.
222 220
exitErr :: String -> IO a
223 221
exitErr errmsg = do
224
  hPutStrLn stderr $ "Error: " ++ errmsg ++ "."
222
  hPutStrLn stderr $ "Error: " ++ errmsg
225 223
  exitWith (ExitFailure 1)
226 224

  
227 225
-- | Exits with an error message if the given boolean condition if true.
b/htools/htools.hs
30 30
import Data.Char (toLower)
31 31
import Prelude hiding (catch)
32 32
import System.Environment
33
import System.Exit
34 33
import System.IO
35 34
import System.IO.Error (isDoesNotExistError)
36 35

  
......
45 44
  hPutStrLn stderr "This program must be installed under one of the following\
46 45
                   \ names:"
47 46
  mapM_ (hPutStrLn stderr . ("  - " ++) . fst) personalities
48
  hPutStrLn stderr "Please either rename/symlink the program or set\n\
49
                   \the environment variable HTOOLS to the desired role."
50
  exitWith $ ExitFailure 1
47
  exitErr "Please either rename/symlink the program or set\n\
48
          \the environment variable HTOOLS to the desired role."
51 49

  
52 50
main :: IO ()
53 51
main = do
b/htools/rpc-test.hs
37 37
usage :: IO ()
38 38
usage = do
39 39
  prog <- getProgName
40
  hPutStrLn stderr $ "Usage: " ++ prog ++ " delay node..."
41
  exitWith $ ExitFailure 1
40
  exitErr "Usage: " ++ prog ++ " delay node..."
42 41

  
43 42
main :: IO ()
44 43
main = do

Also available in: Unified diff