Nuke.Cola
Loading...
Searching...
No Matches
Nuke.Cola.ErrorHandling Class Reference

Static Public Member Functions

static ValueOrError< T > TryGet< T > (Func< T > getter, Action< Exception >? onFailure=null, Exception[]? previousErrors=null)
 Try to gwt a value from an input function which may throw an exception. If an exception is thrown then wrap it inside a ValueOrError for others to handle.
 
static ValueOrError< TResult > Transform< TResult, TInput > (this ValueOrError< TInput > self, Func< TInput, TResult > transform)
 Work on the value inside a ValueOrError but only if input ValueOrError is valid. Return aggregated errors otherwise.
 
static ValueOrError< T > Else< T > (this ValueOrError< T > self, Func< T > getter, Action< Exception >? onFailure=null)
 If input ValueOrError is an error then attempt to execute the input getter function (which may also fail) If input ValueOrError is a value then just return that immediately.
 
static ValueOrError< T > Else< T > (this ValueOrError< T > self, bool condition, Func< T > getter, Action< Exception >? onFailure=null)
 If input ValueOrError is an error then attempt to execute the input getter function (which may also fail) only when condition is true. If condition is false or when input ValueOrError is a value then just return that immediately.
 
static T Get< T > (this ValueOrError< T > self, string? message=null)
 Guarantee the result of an input ValueOrError otherwise throw the aggregated exceptions inside the error.
 
static Attempt Try (Action action, Action< Exception >? onFailure=null, Exception[]? previousErrors=null)
 Attempt to try something which may throw an exception. If an exception is thrown then wrap it inside a ValueOrError for others to handle.
 
static Attempt Else (this Attempt self, Action action, Action< Exception >? onFailure=null)
 If input attempt is an error then attempt to execute another input action (which may also fail)
 
static Attempt Else (this Attempt self, bool condition, Action action, Action< Exception >? onFailure=null)
 If input attempt is an error then attempt to execute another input action (which may also fail) only when condition is true.
 
static void Assume (this Attempt self, string? message=null)
 Guarantee that one of the chain of attempts proceeding this function has succeeded otherwise throw the aggregated exceptions inside the error.
 

Detailed Description

Definition at line 33 of file ErrorHandling.cs.

Member Function Documentation

◆ Assume()

static void Nuke.Cola.ErrorHandling.Assume ( this Attempt self,
string? message = null )
static

Guarantee that one of the chain of attempts proceeding this function has succeeded otherwise throw the aggregated exceptions inside the error.

Parameters
self
messageOptional message for when input is an error

Definition at line 184 of file ErrorHandling.cs.

◆ Else() [1/2]

static Attempt Nuke.Cola.ErrorHandling.Else ( this Attempt self,
Action action,
Action< Exception >? onFailure = null )
static

If input attempt is an error then attempt to execute another input action (which may also fail)

Parameters
self
actionwhich may throw an exception
onFailureOptionally react to the failure of the action
Returns
An attempt

Definition at line 154 of file ErrorHandling.cs.

◆ Else() [2/2]

static Attempt Nuke.Cola.ErrorHandling.Else ( this Attempt self,
bool condition,
Action action,
Action< Exception >? onFailure = null )
static

If input attempt is an error then attempt to execute another input action (which may also fail) only when condition is true.

Parameters
self
conditionConsider fallback only when this condition is true
actionwhich may throw an exception
onFailureOptionally react to the failure of the action
Returns
The input correct attempt, or if that has failed before then the attempt at this input action, or an error if that also fails.

Definition at line 172 of file ErrorHandling.cs.

◆ Else< T >() [1/2]

static ValueOrError< T > Nuke.Cola.ErrorHandling.Else< T > ( this ValueOrError< T > self,
bool condition,
Func< T > getter,
Action< Exception >? onFailure = null )
static

If input ValueOrError is an error then attempt to execute the input getter function (which may also fail) only when condition is true. If condition is false or when input ValueOrError is a value then just return that immediately.

Parameters
self
conditionConsider fallback only when this condition is true
getterThe function returning T which may however throw an exception
onFailureOptionally react to the failure of the getter function
Returns
The input correct value, or if that's erronous then the result of the getter function, or an error if that also fails.

Definition at line 100 of file ErrorHandling.cs.

◆ Else< T >() [2/2]

static ValueOrError< T > Nuke.Cola.ErrorHandling.Else< T > ( this ValueOrError< T > self,
Func< T > getter,
Action< Exception >? onFailure = null )
static

If input ValueOrError is an error then attempt to execute the input getter function (which may also fail) If input ValueOrError is a value then just return that immediately.

Parameters
self
getterThe function returning T which may however throw an exception
onFailureOptionally react to the failure of the getter function
Returns
The input correct value, or if that's erronous then the result of the getter function, or an error if that also fails.

Definition at line 81 of file ErrorHandling.cs.

◆ Get< T >()

static T Nuke.Cola.ErrorHandling.Get< T > ( this ValueOrError< T > self,
string? message = null )
static

Guarantee the result of an input ValueOrError otherwise throw the aggregated exceptions inside the error.

Parameters
self
messageOptional message for when input is an error
Template Parameters
T
Returns
Guaranteed value (or throwing an exception)

Definition at line 114 of file ErrorHandling.cs.

◆ Transform< TResult, TInput >()

static ValueOrError< TResult > Nuke.Cola.ErrorHandling.Transform< TResult, TInput > ( this ValueOrError< TInput > self,
Func< TInput, TResult > transform )
static

Work on the value inside a ValueOrError but only if input ValueOrError is valid. Return aggregated errors otherwise.

Parameters
self
transform
Template Parameters
TResult
TInput
Returns

Definition at line 63 of file ErrorHandling.cs.

◆ Try()

static Attempt Nuke.Cola.ErrorHandling.Try ( Action action,
Action< Exception >? onFailure = null,
Exception?[] previousErrors = null )
static

Attempt to try something which may throw an exception. If an exception is thrown then wrap it inside a ValueOrError for others to handle.

Parameters
actionwhich may throw an exception
onFailureOptionally react to the failure of the action
previousErrorsOptionally provide previous failures which has led to this one
Returns
An attempt

Definition at line 131 of file ErrorHandling.cs.

◆ TryGet< T >()

static ValueOrError< T > Nuke.Cola.ErrorHandling.TryGet< T > ( Func< T > getter,
Action< Exception >? onFailure = null,
Exception?[] previousErrors = null )
static

Try to gwt a value from an input function which may throw an exception. If an exception is thrown then wrap it inside a ValueOrError for others to handle.

Parameters
getterThe function returning T which may however throw an exception
onFailureOptionally react to the failure of the getter function
previousErrorsOptionally provide previous failures which has led to this one
Returns
The result of the getter function or an error

Definition at line 43 of file ErrorHandling.cs.


The documentation for this class was generated from the following file: