Browse Source

Unwrap exceptions before logging.

refactor/style-priorities
Steven Kirk 4 years ago
parent
commit
c44e0bda34
  1. 37
      src/Avalonia.Base/PropertyStore/LoggingUtils.cs

37
src/Avalonia.Base/PropertyStore/LoggingUtils.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Avalonia.Data; using Avalonia.Data;
@ -23,7 +24,7 @@ namespace Avalonia.PropertyStore
BindingValue<T> value) BindingValue<T> value)
{ {
if (value.HasError) if (value.HasError)
Log(owner, property, value); Log(owner, property, value.Error!);
} }
public static void LogInvalidValue( public static void LogInvalidValue(
@ -59,25 +60,23 @@ namespace Avalonia.PropertyStore
AvaloniaProperty property, AvaloniaProperty property,
Exception e) Exception e)
{ {
owner.GetBindingWarningLogger(property, e)?.Log( if (e is TargetInvocationException t)
owner, e = t.InnerException!;
"Error in binding to {Target}.{Property}: {Message}",
owner,
property,
e.Message);
}
private static void Log<T>( if (e is AggregateException a)
AvaloniaObject owner, {
AvaloniaProperty property, foreach (var i in a.InnerExceptions)
BindingValue<T> value) Log(owner, property, i);
{ }
owner.GetBindingWarningLogger(property, value.Error)?.Log( else
owner, {
"Error in binding to {Target}.{Property}: {Message}", owner.GetBindingWarningLogger(property, e)?.Log(
owner, owner,
property, "Error in binding to {Target}.{Property}: {Message}",
value.Error!.Message); owner,
property,
e.Message);
}
} }
} }
} }

Loading…
Cancel
Save