Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / Errors.hs @ ef3ad027

History | View | Annotate | Download (3.8 kB)

1
{-# LANGUAGE TemplateHaskell #-}
2

    
3
{-| Implementation of the Ganeti error types.
4

    
5
This module implements our error hierarchy. Currently we implement one
6
identical to the Python one; later we might one to have separate ones
7
for frontend (clients), master and backend code.
8

    
9
-}
10

    
11
{-
12

    
13
Copyright (C) 2012 Google Inc.
14

    
15
This program is free software; you can redistribute it and/or modify
16
it under the terms of the GNU General Public License as published by
17
the Free Software Foundation; either version 2 of the License, or
18
(at your option) any later version.
19

    
20
This program is distributed in the hope that it will be useful, but
21
WITHOUT ANY WARRANTY; without even the implied warranty of
22
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23
General Public License for more details.
24

    
25
You should have received a copy of the GNU General Public License
26
along with this program; if not, write to the Free Software
27
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28
02110-1301, USA.
29

    
30
-}
31

    
32
module Ganeti.Errors
33
  ( ErrorCode(..)
34
  , GanetiException(..)
35
  , ErrorResult
36
  , excName
37
  ) where
38

    
39
import Text.JSON hiding (Result, Ok)
40

    
41
import Ganeti.THH
42
import Ganeti.BasicTypes
43
import qualified Ganeti.Constants as C
44

    
45
-- | Error code types for 'OpPrereqError'.
46
$(declareSADT "ErrorCode"
47
  [ ("ECodeResolver",  'C.errorsEcodeResolver)
48
  , ("ECodeNoRes",     'C.errorsEcodeNores)
49
  , ("ECodeInval",     'C.errorsEcodeInval)
50
  , ("ECodeState",     'C.errorsEcodeState)
51
  , ("ECodeNoEnt",     'C.errorsEcodeNoent)
52
  , ("ECodeExists",    'C.errorsEcodeExists)
53
  , ("ECodeNotUnique", 'C.errorsEcodeNotunique)
54
  , ("ECodeFault",     'C.errorsEcodeFault)
55
  , ("ECodeEnviron",   'C.errorsEcodeEnviron)
56
  ])
57
$(makeJSONInstance ''ErrorCode)
58

    
59
$(genException "GanetiException"
60
  [ ("GenericError", [excErrMsg])
61
  , ("LockError", [excErrMsg])
62
  , ("PidFileLockError", [excErrMsg])
63
  , ("HypervisorError", [excErrMsg])
64
  , ("ProgrammerError", [excErrMsg])
65
  , ("BlockDeviceError", [excErrMsg])
66
  , ("ConfigurationError", [excErrMsg])
67
  , ("ConfigVersionMismatch", [ ("expCode", [t| Int |])
68
                              , ("actCode", [t| Int |])])
69
  , ("ReservationError", [excErrMsg])
70
  , ("RemoteError", [excErrMsg])
71
  , ("SignatureError", [excErrMsg])
72
  , ("ParameterError", [excErrMsg])
73
  , ("ResultValidationError", [excErrMsg])
74
  , ("OpPrereqError", [excErrMsg, ("errCode", [t| ErrorCode |])])
75
  , ("OpExecError", [excErrMsg])
76
  , ("OpResultError", [excErrMsg])
77
  , ("OpCodeUnknown", [excErrMsg])
78
  , ("JobLost", [excErrMsg])
79
  , ("JobFileCorrupted", [excErrMsg])
80
  , ("ResolverError", [ ("errHostname", [t| String |])
81
                      , ("errResolverCode", [t| Int |])
82
                      , ("errResolverMsg", [t| String |])])
83
  , ("HooksFailure", [excErrMsg])
84
  , ("HooksAbort", [("errs", [t| [(String, String, String)] |])])
85
  , ("UnitParseError", [excErrMsg])
86
  , ("ParseError", [excErrMsg])
87
  , ("TypeEnforcementError", [excErrMsg])
88
  , ("X509CertError", [excErrMsg])
89
  , ("TagError", [excErrMsg])
90
  , ("CommandError", [excErrMsg])
91
  , ("StorageError", [excErrMsg])
92
  , ("InotifyError", [excErrMsg])
93
  , ("JobQueueError", [excErrMsg])
94
  , ("JobQueueDrainError", [excErrMsg])
95
  , ("JobQueueFull", [])
96
  , ("ConfdMagicError", [excErrMsg])
97
  , ("ConfdClientError", [excErrMsg])
98
  , ("UdpDataSizeError", [excErrMsg])
99
  , ("NoCtypesError", [excErrMsg])
100
  , ("IPAddressError", [excErrMsg])
101
  , ("LuxiError", [excErrMsg])
102
  , ("QueryFilterParseError", [excErrMsg]) -- not consistent with Python
103
  , ("RapiTestResult", [excErrMsg])
104
  , ("FileStoragePathError", [excErrMsg])
105
  ])
106

    
107
instance JSON GanetiException where
108
  showJSON = saveGanetiException
109
  readJSON = loadGanetiException
110

    
111
instance FromString GanetiException where
112
  mkFromString = GenericError
113

    
114
-- | Error monad using 'GanetiException' type alias.
115
type ErrorResult = GenericResult GanetiException
116

    
117
$(genStrOfOp ''GanetiException "excName")