Move a node-specific function to Query.Node
[ganeti-local] / htools / Ganeti / Errors.hs
index 391e379..1eedf6c 100644 (file)
@@ -33,8 +33,9 @@ module Ganeti.Errors
   ( ErrorCode(..)
   , GanetiException(..)
   , ErrorResult
-  , excName
+  , errToResult
   , errorExitCode
+  , excName
   , formatError
   ) where
 
@@ -49,6 +50,7 @@ import qualified Ganeti.Constants as C
 $(declareSADT "ErrorCode"
   [ ("ECodeResolver",  'C.errorsEcodeResolver)
   , ("ECodeNoRes",     'C.errorsEcodeNores)
+  , ("ECodeTempNoRes", 'C.errorsEcodeTempNores)
   , ("ECodeInval",     'C.errorsEcodeInval)
   , ("ECodeState",     'C.errorsEcodeState)
   , ("ECodeNoEnt",     'C.errorsEcodeNoent)
@@ -67,8 +69,8 @@ $(genException "GanetiException"
   , ("ProgrammerError", [excErrMsg])
   , ("BlockDeviceError", [excErrMsg])
   , ("ConfigurationError", [excErrMsg])
-  , ("ConfigVersionMismatch", [ ("expCode", [t| Int |])
-                              , ("actCode", [t| Int |])])
+  , ("ConfigVersionMismatch", [ ("expVer", [t| Int |])
+                              , ("actVer", [t| Int |])])
   , ("ReservationError", [excErrMsg])
   , ("RemoteError", [excErrMsg])
   , ("SignatureError", [excErrMsg])
@@ -88,7 +90,8 @@ $(genException "GanetiException"
   , ("UnitParseError", [excErrMsg])
   , ("ParseError", [excErrMsg])
   , ("TypeEnforcementError", [excErrMsg])
-  , ("X509CertError", [excErrMsg])
+  , ("X509CertError", [ ("certFileName", [t| String |])
+                      , excErrMsg ])
   , ("TagError", [excErrMsg])
   , ("CommandError", [excErrMsg])
   , ("StorageError", [excErrMsg])
@@ -169,3 +172,8 @@ formatError (GenericError msg) =
   "Unhandled Ganeti error: " ++ msg
 formatError err =
   "Unhandled exception: " ++ show err
+
+-- | Convert from an 'ErrorResult' to a standard 'Result'.
+errToResult :: ErrorResult a -> Result a
+errToResult (Ok a)  = Ok a
+errToResult (Bad e) = Bad $ formatError e