< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.Workflows.Sequential.FallbackExecutor
Assembly: NexusLabs.Needlr.AgentFramework.Workflows
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework.Workflows/Sequential/FallbackExecutor.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 48
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ExecuteAsync()100%11100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework.Workflows/Sequential/FallbackExecutor.cs

#LineLine coverage
 1namespace NexusLabs.Needlr.AgentFramework.Workflows.Sequential;
 2
 3/// <summary>
 4/// Tries a primary executor and, on failure, falls back to a secondary executor.
 5/// User cancellation is never swallowed.
 6/// </summary>
 7/// <param name="primary">The preferred executor to try first.</param>
 8/// <param name="fallback">The executor to use if the primary throws.</param>
 9/// <param name="shouldFallback">
 10/// Optional predicate controlling which exceptions trigger fallback. When <see langword="null"/>
 11/// (the default), any non-cancellation exception triggers fallback. When provided, only exceptions
 12/// where the predicate returns <see langword="true"/> trigger fallback; others propagate.
 13/// </param>
 14/// <example>
 15/// <code>
 16/// // Default — falls back on any failure
 17/// var executor = new FallbackExecutor(primaryExecutor, fallbackExecutor);
 18///
 19/// // Narrow — only fall back on timeouts
 20/// var executor = new FallbackExecutor(primaryExecutor, fallbackExecutor,
 21///     shouldFallback: ex =&gt; ex is TaskCanceledException or HttpRequestException);
 22/// </code>
 23/// </example>
 24[DoNotAutoRegister]
 1025public sealed class FallbackExecutor(
 1026    IStageExecutor primary,
 1027    IStageExecutor fallback,
 1028    Func<Exception, bool>? shouldFallback = null) : IStageExecutor
 29{
 30    /// <inheritdoc />
 31    public async Task<StageExecutionResult> ExecuteAsync(
 32        StageExecutionContext context,
 33        CancellationToken cancellationToken)
 34    {
 35        try
 36        {
 737            return await primary.ExecuteAsync(context, cancellationToken);
 38        }
 239        catch (OperationCanceledException) when (context.CallerCancellationToken.IsCancellationRequested)
 40        {
 141            throw;
 42        }
 443        catch (Exception ex) when (shouldFallback is null || shouldFallback(ex))
 44        {
 345            return await fallback.ExecuteAsync(context, cancellationToken);
 46        }
 547    }
 48}