Move FileDriver from Objects to Types
[ganeti-local] / htools / Ganeti / Errors.hs
index 391e379..92678df 100644 (file)
@@ -33,8 +33,9 @@ module Ganeti.Errors
   ( ErrorCode(..)
   , GanetiException(..)
   , ErrorResult
-  , excName
+  , errToResult
   , errorExitCode
+  , excName
   , formatError
   ) where
 
@@ -67,8 +68,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 +89,8 @@ $(genException "GanetiException"
   , ("UnitParseError", [excErrMsg])
   , ("ParseError", [excErrMsg])
   , ("TypeEnforcementError", [excErrMsg])
-  , ("X509CertError", [excErrMsg])
+  , ("X509CertError", [ ("certFileName", [t| String |])
+                      , excErrMsg ])
   , ("TagError", [excErrMsg])
   , ("CommandError", [excErrMsg])
   , ("StorageError", [excErrMsg])
@@ -169,3 +171,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