< Summary

Information
Class: DirectSight.Common.ExceptionExtensions
Assembly DirectSight
File(s): /home/runner/work/DirectSight/DirectSight/DirectSight/Common/ExceptionExtensions.cs
Line coverage
29%
Covered lines: 9
Uncovered lines: 22
Coverable lines: 31
Total lines: 59
Line coverage: 29%
Branch coverage
28%
Covered branches: 4
Total branches: 14
Branch coverage: 28.5%
Method coverage

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
GetExceptionMessageForDisplay(...)28.57%141429.03%

File(s)

/home/runner/work/DirectSight/DirectSight/DirectSight/Common/ExceptionExtensions.cs

#LineLine coverage
 1using System;
 2using System.Reflection;
 3using System.Text;
 4
 5namespace DirectSight.Common;
 6
 7/// <summary>
 8/// Exception extensions.
 9/// </summary>
 10internal static class ExceptionExtensions
 11{
 12    /// <summary>
 13    /// Gets a full error message especially for <see cref="AggregateException"/>.
 14    /// </summary>
 15    /// <param name="exception">The exception.</param>
 16    /// <returns>The error message.</returns>
 17    public static string GetExceptionMessageForDisplay(this Exception exception)
 218    {
 219        if (exception == null)
 020        {
 021            throw new ArgumentNullException(nameof(exception));
 22        }
 23
 224        string message = exception.Message;
 25
 226        if (exception is AggregateException aggregate)
 027        {
 028            var flat = aggregate.Flatten();
 29
 030            if (flat.InnerExceptions.Count == 1)
 031            {
 32                // recalling as we potentially can have a targetinvocationexception
 033                message = GetExceptionMessageForDisplay(flat.InnerException);
 034            }
 035            else if (flat.InnerExceptions.Count > 0)
 036            {
 037                var bldr = new StringBuilder();
 38
 039                bldr.AppendLine("Multiple errors");
 40
 041                foreach (var innerEx in flat.InnerExceptions)
 042                {
 043                    bldr.AppendLine(GetExceptionMessageForDisplay(innerEx));
 044                }
 45
 046                message = bldr.ToString();
 047            }
 048        }
 49        else
 250        {
 251            if (exception is TargetInvocationException targetInvocationEx && targetInvocationEx.InnerException != null)
 052            {
 053                message = GetExceptionMessageForDisplay(targetInvocationEx.InnerException);
 054            }
 255        }
 56
 257        return message;
 258    }
 59}