+13
-7
@@ -14,7 +14,13 @@ public abstract class Error : IEquatable<Error>, IComparable<Error>
|
||||
/// </summary>
|
||||
/// <param name="thisException">Exception</param>
|
||||
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Error New(Exception thisException) => new ExceptionalError(thisException);
|
||||
public static Error New(Exception thisException) => thisException switch
|
||||
{
|
||||
AggregateException { InnerExceptions.Count: > 1 } aggegateException => new ManyErrors(aggegateException.InnerExceptions.Select(x => Error.New(x))),
|
||||
AggregateException { InnerExceptions.Count: 1 } aggegateException => new ExceptionalError(aggegateException.InnerExceptions[0]),
|
||||
_ => new ExceptionalError(thisException),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Create a <see cref="ExceptionalError"/> with an overriden detail. This can be useful for sanitising the display message
|
||||
/// when internally we're carrying the exception.
|
||||
@@ -85,7 +91,7 @@ public abstract class Error : IEquatable<Error>, IComparable<Error>
|
||||
[Pure] public abstract int Count { get; }
|
||||
[Pure] public abstract bool IsEmpty { get; }
|
||||
[Pure] public abstract bool IsExpected { get; }
|
||||
[Pure] public abstract bool IsExeptional { get; }
|
||||
[Pure] public abstract bool IsExceptional { get; }
|
||||
|
||||
[Pure] public Error Append(Error? next)
|
||||
{
|
||||
@@ -166,7 +172,7 @@ public sealed class ExpectedError : Error
|
||||
[Pure] public override int Count => 1;
|
||||
[Pure] public override bool IsEmpty => false;
|
||||
[Pure] public override bool IsExpected => true;
|
||||
[Pure] public override bool IsExeptional => false;
|
||||
[Pure] public override bool IsExceptional => false;
|
||||
|
||||
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override IEnumerable<Error> ToEnumerable()
|
||||
@@ -208,7 +214,7 @@ public sealed class ExceptionalError : Error
|
||||
[Pure] public override int Count => 1;
|
||||
[Pure] public override bool IsEmpty => false;
|
||||
[Pure] public override bool IsExpected => false;
|
||||
[Pure] public override bool IsExeptional => true;
|
||||
[Pure] public override bool IsExceptional => true;
|
||||
|
||||
[Pure] public override Exception ToException() => Exception ?? base.ToException();
|
||||
|
||||
@@ -220,7 +226,7 @@ public sealed class ExceptionalError : Error
|
||||
|
||||
private static ImmutableDictionary<string, string> ExtractExtensionData(Exception exception)
|
||||
{
|
||||
if (!(exception.Data?.Count > 0))
|
||||
if (exception.Data is null || exception.Data.Count == 0)
|
||||
return ImmutableDictionary<string, string>.Empty;
|
||||
|
||||
var values = GetGenericExtData(exception);
|
||||
@@ -276,7 +282,7 @@ public sealed class ManyErrors : Error, IEnumerable<Error>, IReadOnlyList<Error>
|
||||
{
|
||||
var unpackedErrors = ImmutableArray.CreateBuilder<Error>();
|
||||
|
||||
foreach (var err in errors)
|
||||
foreach (var err in errors.Where(x => x is not null))
|
||||
{
|
||||
if (err.IsEmpty) continue;
|
||||
|
||||
@@ -309,7 +315,7 @@ public sealed class ManyErrors : Error, IEnumerable<Error>, IReadOnlyList<Error>
|
||||
[Pure] public override int Count => _errors.Length;
|
||||
[Pure] public override bool IsEmpty => _errors.IsEmpty;
|
||||
[Pure] public override bool IsExpected => _errors.All(static x => x.IsExpected);
|
||||
[Pure] public override bool IsExeptional => _errors.Any(static x => x.IsExeptional);
|
||||
[Pure] public override bool IsExceptional => _errors.Any(static x => x.IsExceptional);
|
||||
|
||||
[Pure] public Error this[int index] => _errors[index];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user