Table of Contents

Class TapOnFailureExtensions

Namespace
Trellis
Assembly
Trellis.Core.dll

Provides extension methods for executing side effects on failed Results without changing the Result.

public static class TapOnFailureExtensions
Inheritance
TapOnFailureExtensions
Inherited Members

Examples

var result = GetUser(id)
    .TapOnFailure(error => _logger.LogError("Failed to get user: {Error}", error.Detail))
    .TapOnFailure(() => _metrics.IncrementCounter("user.get.failed"));
var result = EmailAddress.TryCreate("invalid-email")
    .Combine(UserId.TryCreate("123"))
    .TapOnFailure(error => _logger.LogError("Validation failed: {Error}", error.Detail))
    .TapOnFailure(error => _metrics.RecordValidationFailure())
    .Bind((email, userId) => CreateUser(email, userId));

Remarks

TapOnFailure is the counterpart to TapExtensions. It allows you to perform side effects (like logging, metrics, or debugging) when a Result is in a failed state, without altering the Result itself. The action is only executed if the Result is a failure, and the original Result is always returned unchanged.

This operation runs on the failure track - it only executes when the Result has failed. If the Result is successful, the operation is skipped entirely.

Methods

TapOnFailure<TValue>(Result<TValue>, Action)

Executes the given action if the result is a failure. Returns the original result unchanged.

[RailwayTrack(TrackBehavior.Failure)]
public static Result<TValue> TapOnFailure<TValue>(this Result<TValue> result, Action action)

Parameters

result Result<TValue>

The result to tap.

action Action

The action to execute if the result is a failure.

Returns

Result<TValue>

The original result unchanged.

Type Parameters

TValue

Type of the result value.

Remarks

This operation runs on the failure track only. If the result is successful, the action is not executed.

TapOnFailure<TValue>(Result<TValue>, Action<Error>)

Executes the given action with the error if the result is a failure. Returns the original result unchanged.

[RailwayTrack(TrackBehavior.Failure)]
public static Result<TValue> TapOnFailure<TValue>(this Result<TValue> result, Action<Error> action)

Parameters

result Result<TValue>

The result to tap.

action Action<Error>

The action to execute with the error if the result is a failure.

Returns

Result<TValue>

The original result unchanged.

Type Parameters

TValue

Type of the result value.

Remarks

This operation runs on the failure track only. If the result is successful, the action is not executed. The error object is passed to the action for inspection or logging.

TapOnFailure<T1, T2>(Result<(T1, T2)>, Action)

Executes a side effect action when the 2-element tuple result is a failure.

public static Result<(T1, T2)> TapOnFailure<T1, T2>(this Result<(T1, T2)> result, Action action)

Parameters

result Result<(T1, T2)>

The result containing a 2-element tuple.

action Action

The side effect action to execute on failure.

Returns

Result<(T1, T2)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

Remarks

If the result is successful, the action is not executed and the success is returned unchanged. This is the inverse of Tap, executing only on the error track.

TapOnFailure<T1, T2>(Result<(T1, T2)>, Action<Error>)

Executes a side effect action with the error when the 2-element tuple result is a failure.

public static Result<(T1, T2)> TapOnFailure<T1, T2>(this Result<(T1, T2)> result, Action<Error> action)

Parameters

result Result<(T1, T2)>

The result containing a 2-element tuple.

action Action<Error>

The side effect action to execute with the error on failure.

Returns

Result<(T1, T2)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

Examples

.TapOnFailure(error => _logger.LogError("Error: {Code} - {Detail}", error.Code, error.Detail))

Remarks

This overload provides access to the Error object for detailed error logging or handling.

TapOnFailure<T1, T2, T3>(Result<(T1, T2, T3)>, Action)

Executes a side effect action when the 3-element tuple result is a failure.

public static Result<(T1, T2, T3)> TapOnFailure<T1, T2, T3>(this Result<(T1, T2, T3)> result, Action action)

Parameters

result Result<(T1, T2, T3)>

The result containing a 3-element tuple.

action Action

The side effect action to execute on failure.

Returns

Result<(T1, T2, T3)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

Remarks

If the result is successful, the action is not executed and the success is returned unchanged. This is the inverse of Tap, executing only on the error track.

TapOnFailure<T1, T2, T3>(Result<(T1, T2, T3)>, Action<Error>)

Executes a side effect action with the error when the 3-element tuple result is a failure.

public static Result<(T1, T2, T3)> TapOnFailure<T1, T2, T3>(this Result<(T1, T2, T3)> result, Action<Error> action)

Parameters

result Result<(T1, T2, T3)>

The result containing a 3-element tuple.

action Action<Error>

The side effect action to execute with the error on failure.

Returns

Result<(T1, T2, T3)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

Examples

.TapOnFailure(error => _logger.LogError("Error: {Code} - {Detail}", error.Code, error.Detail))

Remarks

This overload provides access to the Error object for detailed error logging or handling.

TapOnFailure<T1, T2, T3, T4>(Result<(T1, T2, T3, T4)>, Action)

Executes a side effect action when the 4-element tuple result is a failure.

public static Result<(T1, T2, T3, T4)> TapOnFailure<T1, T2, T3, T4>(this Result<(T1, T2, T3, T4)> result, Action action)

Parameters

result Result<(T1, T2, T3, T4)>

The result containing a 4-element tuple.

action Action

The side effect action to execute on failure.

Returns

Result<(T1, T2, T3, T4)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

Remarks

If the result is successful, the action is not executed and the success is returned unchanged. This is the inverse of Tap, executing only on the error track.

TapOnFailure<T1, T2, T3, T4>(Result<(T1, T2, T3, T4)>, Action<Error>)

Executes a side effect action with the error when the 4-element tuple result is a failure.

public static Result<(T1, T2, T3, T4)> TapOnFailure<T1, T2, T3, T4>(this Result<(T1, T2, T3, T4)> result, Action<Error> action)

Parameters

result Result<(T1, T2, T3, T4)>

The result containing a 4-element tuple.

action Action<Error>

The side effect action to execute with the error on failure.

Returns

Result<(T1, T2, T3, T4)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

Examples

.TapOnFailure(error => _logger.LogError("Error: {Code} - {Detail}", error.Code, error.Detail))

Remarks

This overload provides access to the Error object for detailed error logging or handling.

TapOnFailure<T1, T2, T3, T4, T5>(Result<(T1, T2, T3, T4, T5)>, Action)

Executes a side effect action when the 5-element tuple result is a failure.

public static Result<(T1, T2, T3, T4, T5)> TapOnFailure<T1, T2, T3, T4, T5>(this Result<(T1, T2, T3, T4, T5)> result, Action action)

Parameters

result Result<(T1, T2, T3, T4, T5)>

The result containing a 5-element tuple.

action Action

The side effect action to execute on failure.

Returns

Result<(T1, T2, T3, T4, T5)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

T5

The type of element 5 in the tuple.

Remarks

If the result is successful, the action is not executed and the success is returned unchanged. This is the inverse of Tap, executing only on the error track.

TapOnFailure<T1, T2, T3, T4, T5>(Result<(T1, T2, T3, T4, T5)>, Action<Error>)

Executes a side effect action with the error when the 5-element tuple result is a failure.

public static Result<(T1, T2, T3, T4, T5)> TapOnFailure<T1, T2, T3, T4, T5>(this Result<(T1, T2, T3, T4, T5)> result, Action<Error> action)

Parameters

result Result<(T1, T2, T3, T4, T5)>

The result containing a 5-element tuple.

action Action<Error>

The side effect action to execute with the error on failure.

Returns

Result<(T1, T2, T3, T4, T5)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

T5

The type of element 5 in the tuple.

Examples

.TapOnFailure(error => _logger.LogError("Error: {Code} - {Detail}", error.Code, error.Detail))

Remarks

This overload provides access to the Error object for detailed error logging or handling.

TapOnFailure<T1, T2, T3, T4, T5, T6>(Result<(T1, T2, T3, T4, T5, T6)>, Action)

Executes a side effect action when the 6-element tuple result is a failure.

public static Result<(T1, T2, T3, T4, T5, T6)> TapOnFailure<T1, T2, T3, T4, T5, T6>(this Result<(T1, T2, T3, T4, T5, T6)> result, Action action)

Parameters

result Result<(T1, T2, T3, T4, T5, T6)>

The result containing a 6-element tuple.

action Action

The side effect action to execute on failure.

Returns

Result<(T1, T2, T3, T4, T5, T6)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

T5

The type of element 5 in the tuple.

T6

The type of element 6 in the tuple.

Remarks

If the result is successful, the action is not executed and the success is returned unchanged. This is the inverse of Tap, executing only on the error track.

TapOnFailure<T1, T2, T3, T4, T5, T6>(Result<(T1, T2, T3, T4, T5, T6)>, Action<Error>)

Executes a side effect action with the error when the 6-element tuple result is a failure.

public static Result<(T1, T2, T3, T4, T5, T6)> TapOnFailure<T1, T2, T3, T4, T5, T6>(this Result<(T1, T2, T3, T4, T5, T6)> result, Action<Error> action)

Parameters

result Result<(T1, T2, T3, T4, T5, T6)>

The result containing a 6-element tuple.

action Action<Error>

The side effect action to execute with the error on failure.

Returns

Result<(T1, T2, T3, T4, T5, T6)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

T5

The type of element 5 in the tuple.

T6

The type of element 6 in the tuple.

Examples

.TapOnFailure(error => _logger.LogError("Error: {Code} - {Detail}", error.Code, error.Detail))

Remarks

This overload provides access to the Error object for detailed error logging or handling.

TapOnFailure<T1, T2, T3, T4, T5, T6, T7>(Result<(T1, T2, T3, T4, T5, T6, T7)>, Action)

Executes a side effect action when the 7-element tuple result is a failure.

public static Result<(T1, T2, T3, T4, T5, T6, T7)> TapOnFailure<T1, T2, T3, T4, T5, T6, T7>(this Result<(T1, T2, T3, T4, T5, T6, T7)> result, Action action)

Parameters

result Result<(T1, T2, T3, T4, T5, T6, T7)>

The result containing a 7-element tuple.

action Action

The side effect action to execute on failure.

Returns

Result<(T1, T2, T3, T4, T5, T6, T7)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

T5

The type of element 5 in the tuple.

T6

The type of element 6 in the tuple.

T7

The type of element 7 in the tuple.

Remarks

If the result is successful, the action is not executed and the success is returned unchanged. This is the inverse of Tap, executing only on the error track.

TapOnFailure<T1, T2, T3, T4, T5, T6, T7>(Result<(T1, T2, T3, T4, T5, T6, T7)>, Action<Error>)

Executes a side effect action with the error when the 7-element tuple result is a failure.

public static Result<(T1, T2, T3, T4, T5, T6, T7)> TapOnFailure<T1, T2, T3, T4, T5, T6, T7>(this Result<(T1, T2, T3, T4, T5, T6, T7)> result, Action<Error> action)

Parameters

result Result<(T1, T2, T3, T4, T5, T6, T7)>

The result containing a 7-element tuple.

action Action<Error>

The side effect action to execute with the error on failure.

Returns

Result<(T1, T2, T3, T4, T5, T6, T7)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

T5

The type of element 5 in the tuple.

T6

The type of element 6 in the tuple.

T7

The type of element 7 in the tuple.

Examples

.TapOnFailure(error => _logger.LogError("Error: {Code} - {Detail}", error.Code, error.Detail))

Remarks

This overload provides access to the Error object for detailed error logging or handling.

TapOnFailure<T1, T2, T3, T4, T5, T6, T7, T8>(Result<(T1, T2, T3, T4, T5, T6, T7, T8)>, Action)

Executes a side effect action when the 8-element tuple result is a failure.

public static Result<(T1, T2, T3, T4, T5, T6, T7, T8)> TapOnFailure<T1, T2, T3, T4, T5, T6, T7, T8>(this Result<(T1, T2, T3, T4, T5, T6, T7, T8)> result, Action action)

Parameters

result Result<(T1, T2, T3, T4, T5, T6, T7, T8)>

The result containing a 8-element tuple.

action Action

The side effect action to execute on failure.

Returns

Result<(T1, T2, T3, T4, T5, T6, T7, T8)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

T5

The type of element 5 in the tuple.

T6

The type of element 6 in the tuple.

T7

The type of element 7 in the tuple.

T8

The type of element 8 in the tuple.

Remarks

If the result is successful, the action is not executed and the success is returned unchanged. This is the inverse of Tap, executing only on the error track.

TapOnFailure<T1, T2, T3, T4, T5, T6, T7, T8>(Result<(T1, T2, T3, T4, T5, T6, T7, T8)>, Action<Error>)

Executes a side effect action with the error when the 8-element tuple result is a failure.

public static Result<(T1, T2, T3, T4, T5, T6, T7, T8)> TapOnFailure<T1, T2, T3, T4, T5, T6, T7, T8>(this Result<(T1, T2, T3, T4, T5, T6, T7, T8)> result, Action<Error> action)

Parameters

result Result<(T1, T2, T3, T4, T5, T6, T7, T8)>

The result containing a 8-element tuple.

action Action<Error>

The side effect action to execute with the error on failure.

Returns

Result<(T1, T2, T3, T4, T5, T6, T7, T8)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

T5

The type of element 5 in the tuple.

T6

The type of element 6 in the tuple.

T7

The type of element 7 in the tuple.

T8

The type of element 8 in the tuple.

Examples

.TapOnFailure(error => _logger.LogError("Error: {Code} - {Detail}", error.Code, error.Detail))

Remarks

This overload provides access to the Error object for detailed error logging or handling.

TapOnFailure<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Result<(T1, T2, T3, T4, T5, T6, T7, T8, T9)>, Action)

Executes a side effect action when the 9-element tuple result is a failure.

public static Result<(T1, T2, T3, T4, T5, T6, T7, T8, T9)> TapOnFailure<T1, T2, T3, T4, T5, T6, T7, T8, T9>(this Result<(T1, T2, T3, T4, T5, T6, T7, T8, T9)> result, Action action)

Parameters

result Result<(T1, T2, T3, T4, T5, T6, T7, T8, T9)>

The result containing a 9-element tuple.

action Action

The side effect action to execute on failure.

Returns

Result<(T1, T2, T3, T4, T5, T6, T7, T8, T9)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

T5

The type of element 5 in the tuple.

T6

The type of element 6 in the tuple.

T7

The type of element 7 in the tuple.

T8

The type of element 8 in the tuple.

T9

The type of element 9 in the tuple.

Remarks

If the result is successful, the action is not executed and the success is returned unchanged. This is the inverse of Tap, executing only on the error track.

TapOnFailure<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Result<(T1, T2, T3, T4, T5, T6, T7, T8, T9)>, Action<Error>)

Executes a side effect action with the error when the 9-element tuple result is a failure.

public static Result<(T1, T2, T3, T4, T5, T6, T7, T8, T9)> TapOnFailure<T1, T2, T3, T4, T5, T6, T7, T8, T9>(this Result<(T1, T2, T3, T4, T5, T6, T7, T8, T9)> result, Action<Error> action)

Parameters

result Result<(T1, T2, T3, T4, T5, T6, T7, T8, T9)>

The result containing a 9-element tuple.

action Action<Error>

The side effect action to execute with the error on failure.

Returns

Result<(T1, T2, T3, T4, T5, T6, T7, T8, T9)>

The original result unchanged.

Type Parameters

T1

The type of element 1 in the tuple.

T2

The type of element 2 in the tuple.

T3

The type of element 3 in the tuple.

T4

The type of element 4 in the tuple.

T5

The type of element 5 in the tuple.

T6

The type of element 6 in the tuple.

T7

The type of element 7 in the tuple.

T8

The type of element 8 in the tuple.

T9

The type of element 9 in the tuple.

Examples

.TapOnFailure(error => _logger.LogError("Error: {Code} - {Detail}", error.Code, error.Detail))

Remarks

This overload provides access to the Error object for detailed error logging or handling.