< Summary

Information
Class: Elsa.Resilience.TransientExceptionDetector
Assembly: Elsa.Resilience.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Resilience.Core/Services/TransientExceptionDetector.cs
Line coverage
93%
Covered lines: 14
Uncovered lines: 1
Coverable lines: 15
Total lines: 42
Line coverage: 93.3%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
IsTransient(...)90%101092.3%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Resilience.Core/Services/TransientExceptionDetector.cs

#LineLine coverage
 1namespace Elsa.Resilience;
 2
 3/// <summary>
 4/// Default implementation of <see cref="ITransientExceptionDetector"/> that delegates to registered detectors.
 5/// </summary>
 106public class TransientExceptionDetector(IEnumerable<ITransientExceptionStrategy> detectors) : ITransientExceptionDetecto
 7{
 108    private readonly IReadOnlyList<ITransientExceptionStrategy> _detectors = detectors.ToList();
 9
 10    /// <inheritdoc />
 11    public bool IsTransient(Exception exception)
 12    {
 2813        var detectorsList = _detectors;
 14
 15        // Handle aggregate exceptions specially to avoid redundant checks
 2816        if (exception is AggregateException aggregateException)
 17        {
 18            // Check the aggregate exception itself
 619            if (detectorsList.Any(detector => detector.IsTransient(aggregateException)))
 020                return true;
 21
 22            // Recursively check each inner exception (this will walk their chains)
 323            if (aggregateException.InnerExceptions.Any(IsTransient))
 224                return true;
 25
 126            return false;
 27        }
 28
 29        // Walk the exception chain for non-aggregate exceptions
 2530        var currentException = exception;
 3331        while (currentException != null)
 32        {
 33            // Check if any detector identifies this exception as transient
 5734            if (detectorsList.Any(detector => detector.IsTransient(currentException)))
 2035                return true;
 36
 837            currentException = currentException.InnerException;
 38        }
 39
 540        return false;
 41    }
 42}