ganeti

Safe HaskellSafe-Infered

Ganeti.BasicTypes

Contents

Synopsis

Documentation

data GenericResult a b Source

Generic monad for our error handling mechanisms.

Constructors

Bad a 
Ok b 

Instances

FromString a => MonadError a (GenericResult a) 
FromString a => Monad (GenericResult a)

Monad instance for GenericResult.

Functor (GenericResult a) 
(FromString a, Monoid a) => MonadPlus (GenericResult a) 
Applicative (GenericResult a) 
(FromString a, Monoid a) => Alternative (GenericResult a) 
Arbitrary a => Arbitrary (Result a) 
Arbitrary a => Arbitrary (OpResult a) 
(Eq a, Eq b) => Eq (GenericResult a b) 
(Show a, Show b) => Show (GenericResult a b) 

genericResult :: (a -> c) -> (b -> c) -> GenericResult a b -> cSource

Sum type structure of GenericResult.

type Result = GenericResult StringSource

Type alias for a string Result.

class FromString a whereSource

Type class for things that can be built from strings.

Methods

mkFromString :: String -> aSource

Instances

FromString IOError 
FromString FailMode

FromString instance for FailMode designed to catch unintended use as a general monad.

FromString GanetiException 
FromString [Char]

Trivial String instance; requires FlexibleInstances extension though.

newtype ResultT a m b Source

This is a monad transformation for Result. It's implementation is based on the implementations of MaybeT and ErrorT.

ResultT is very similar to ErrorT, but with one subtle difference: If mplus combines two failing operations, errors of both of them are combined.

Constructors

ResultT 

Fields

runResultT :: m (GenericResult a b)
 

Instances

(MonadBase IO m, FromString a) => MonadBase IO (ResultT a m) 
(FromString a, MonadBaseControl IO m) => MonadBaseControl IO (ResultT a m) 
(Monad m, FromString a) => MonadError a (ResultT a m) 
MonadTrans (ResultT a) 
FromString a => MonadTransControl (ResultT a) 
(Monad m, FromString a) => Monad (ResultT a m) 
Monad m => Functor (ResultT a m) 
(Monad m, FromString a, Monoid a) => MonadPlus (ResultT a m) 
(Monad m, FromString a) => Applicative (ResultT a m) 
(Monad m, FromString a, Monoid a) => Alternative (ResultT a m) 
(MonadIO m, FromString a) => MonadIO (ResultT a m)

The instance catches any IOError using try and converts it into an error message using mkFromString.

This way, monadic code within ResultT that uses solely liftIO to include IO actions ensures that all IO exceptions are handled.

Other exceptions (see instances of Exception) are not currently handled. This might be revised in the future.

(MonadLog m, FromString e) => MonadLog (ResultT e m) 

elimResultT :: Monad m => (a -> ResultT a' m b') -> (b -> ResultT a' m b') -> ResultT a m b -> ResultT a' m b'Source

withError :: MonadError e m => (e' -> e) -> GenericResult e' a -> m aSource

Changes the error message of a result value, if present. Note that since GenericResult is also a MonadError, this function is a generalization of (Error e') => (e' -> e) -> GenericResult e' a -> GenericResult e a

withErrorT :: (Monad m, FromString e) => (e' -> e) -> ResultT e' m a -> ResultT e m aSource

Changes the error message of a ResultT value, if present.

toError :: MonadError e m => GenericResult e a -> m aSource

Lift a Result value to any MonadError. Since ResultT is itself its instance, it's a generalization of Monad m => GenericResult a b -> ResultT a m b.

toErrorBase :: (MonadBase b m, MonadError e m) => ResultT e b a -> m aSource

Lift a ResultT value into any MonadError with the same base monad.

toErrorStr :: (MonadError e m, FromString e) => Result a -> m aSource

An alias for withError mkFromString, which is often used to lift a pure error to a monad stack. See also annotateResult.

tryError :: MonadError e m => m a -> m (Either e a)Source

Run a given computation and if an error occurs, return it as Left of Either. This is a generalized version of try.

mkResultT :: (Monad m, FromString e) => m (Result a) -> ResultT e m aSource

Converts a monadic result with a String message into a ResultT with an arbitrary Error.

Expects that the given action has already taken care of any possible errors. In particular, if applied on IO (Result a), any exceptions should be handled by the given action.

See also toErrorStr.

mkResultT' :: (Monad m, FromString e, Show s) => m (GenericResult s a) -> ResultT e m aSource

Generalisation of mkResultT accepting any showable failures.

isOk :: GenericResult a b -> BoolSource

Simple checker for whether a GenericResult is OK.

isBad :: GenericResult a b -> BoolSource

Simple checker for whether a GenericResult is a failure.

justOk :: [GenericResult a b] -> [b]Source

Simple filter returning only OK values of GenericResult

justBad :: [GenericResult a b] -> [a]Source

Simple filter returning only Bad values of GenericResult

eitherToResult :: Either a b -> GenericResult a bSource

Converter from Either to GenericResult.

isLeft :: Either a b -> BoolSource

Check if an either is Left. Equivalent to isLeft from Data.Either version 4.7.0.0 or higher.

isRight :: Either a b -> BoolSource

Check if an either is Right. Equivalent to isRight from Data.Either version 4.7.0.0 or higher.

annotateResult :: (MonadError e m, FromString e) => String -> Result a -> m aSource

Annotate an error with an ownership information, lifting it to a MonadError. Since Result is an instance of MonadError itself, it's a generalization of type String -> Result a -> Result a. See also toErrorStr.

annotateError :: (MonadError e m, FromString e, Monoid e) => String -> m a -> m aSource

Annotate an error with an ownership information inside a MonadError. See also annotateResult.

failError :: (MonadError e m, FromString e) => String -> m aSource

Throws a String message as an error in a MonadError. This is a generalization of Bad. It's similar to fail, but works within a MonadError, avoiding the unsafe nature of fail.

handleErrorT :: (Monad m, FromString e) => (e' -> ResultT e m a) -> ResultT e' m a -> ResultT e m aSource

A synonym for flip catchErrorT.

catchErrorT :: (Monad m, FromString e) => ResultT e' m a -> (e' -> ResultT e m a) -> ResultT e m aSource

Catches an error in a ResultT value. This is similar to catchError, but in addition allows to change the error type.

orElse :: MonadError e m => m a -> m a -> m aSource

If the first computation fails, run the second one. Unlike mplus instance for ResultT, this doesn't require the Monoid constrait.

iterateOk :: (a -> GenericResult b a) -> a -> [a]Source

Iterate while Ok.

Misc functionality

selectSource

Arguments

:: a

default result

-> [(Bool, a)]

list of "condition, result"

-> a

first result which has a True condition, or default

Return the first result with a True condition, or the default otherwise.

runListHead :: a -> (b -> a) -> [b] -> aSource

Apply a function to the first element of a list, return the default value, if the list is empty. This is just a convenient combination of maybe and listToMaybe.

Lookup of partial names functionality

data MatchPriority Source

The priority of a match in a lookup result.

data LookupResult Source

The result of a name lookup in a list.

Constructors

LookupResult 

Fields

lrMatchPriority :: MatchPriority

The result type | Matching value (for ExactMatch, PartialMatch), Lookup string otherwise

lrContent :: String
 

Instances

Eq LookupResult

Lookup results have an absolute preference ordering.

Ord LookupResult 
Show LookupResult 

prefixMatchSource

Arguments

:: String

Lookup

-> String

Full name

-> Bool

Whether there is a prefix match

Check for prefix matches in names. Implemented in Ganeti core utils.text.MatchNameComponent as the regexp r^%s(..*)?$ % re.escape(key)

goodMatchPriority :: MatchPriority -> BoolSource

Is the lookup priority a good one?

goodLookupResult :: LookupResult -> BoolSource

Is the lookup result an actual match?

compareNameComponentSource

Arguments

:: String

Canonical (target) name

-> String

Partial (lookup) name

-> LookupResult

Result of the lookup

Compares a canonical name and a lookup string.

lookupNameSource

Arguments

:: [String]

List of keys

-> String

Lookup string

-> LookupResult

Result of the lookup

Find the canonical name for a lookup string in a list of names.

newtype ListSet a Source

Wrapper for a Haskell Set

This type wraps a Set and it is used in the Haskell to Python opcode generation to transform a Haskell Set into a Python list without duplicate elements.

Constructors

ListSet 

Fields

unListSet :: Set a
 

Instances

Eq a => Eq (ListSet a) 
Ord a => Ord (ListSet a) 
Show a => Show (ListSet a) 
(Ord a, JSON a) => JSON (ListSet a) 
PyValue a => PyValue (ListSet a) 

newtype Down a Source

Constructors

Down a 

Instances

Eq a => Eq (Down a) 
Ord a => Ord (Down a) 
Read a => Read (Down a) 
Show a => Show (Down a)