Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions src/ModularPipelines/Engine/Execution/ModuleResultFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,45 @@ public static ModuleResult<T> CreateSuccess<T>(T value, ModuleExecutionContext c
}

/// <summary>
/// Creates a failure ModuleResult for the specified exception.
/// Creates a failure ModuleResult for the specified exception (generic version).
/// </summary>
public static ModuleResult<T> CreateFailure<T>(Exception exception, ModuleExecutionContext ctx)
{
return ModuleResult<T>.CreateFailure(exception, ctx);
}

/// <summary>
/// Creates a skipped ModuleResult for the specified skip decision.
/// Creates a failure ModuleResult for the specified exception (non-generic version).
/// </summary>
/// <remarks>
/// This returns the non-generic <see cref="ModuleResult.Failure"/> type, which can be
/// implicitly converted to <see cref="ModuleResult{T}"/> for any T.
/// </remarks>
public static ModuleResult.Failure CreateFailure(Exception exception, ModuleExecutionContext ctx)
{
return ModuleResult.CreateFailure(exception, ctx);
}

/// <summary>
/// Creates a skipped ModuleResult for the specified skip decision (generic version).
/// </summary>
public static ModuleResult<T> CreateSkipped<T>(SkipDecision decision, ModuleExecutionContext ctx)
{
return ModuleResult<T>.CreateSkipped(decision, ctx);
}

/// <summary>
/// Creates a skipped ModuleResult for the specified skip decision (non-generic version).
/// </summary>
/// <remarks>
/// This returns the non-generic <see cref="ModuleResult.Skipped"/> type, which can be
/// implicitly converted to <see cref="ModuleResult{T}"/> for any T.
/// </remarks>
public static ModuleResult.Skipped CreateSkipped(SkipDecision decision, ModuleExecutionContext ctx)
{
return ModuleResult.CreateSkipped(decision, ctx);
}

/// <summary>
/// Creates a skipped ModuleResult (type-erased version for engine use).
/// </summary>
Expand Down Expand Up @@ -71,6 +95,23 @@ private static IModuleResult CreateFailureGeneric<T>(Exception exception, Module
/// </summary>
public static IModuleResult WithStatus(IModuleResult result, Status status)
{
// Handle non-generic Failure/Skipped types directly (most efficient path)
if (result is ModuleResult.Failure failure)
{
return failure with { ModuleStatus = status };
}

if (result is ModuleResult.Skipped skipped)
{
return skipped with { ModuleStatus = status };
}

// For generic types (Success, FailureWrapper, SkippedWrapper), we need to use
// reflection to call WithStatusGeneric<T> which handles the 'with' expression.
// Wrapper types (FailureWrapper/SkippedWrapper) implement IFailureResult/ISkippedResult
// but require the generic path to maintain proper type safety. The wrapper's _inner
// field is private and all metadata is copied to the wrapper's own properties, so
// using 'with' on the wrapper correctly updates the observable ModuleStatus.
var resultType = result.GetType();

// Get the generic type argument from ModuleResult<T>
Expand Down
Loading
Loading