Skip to content

Commit

Permalink
Merge pull request #8252 from AvaloniaUI/safe-log-typed-adapter
Browse files Browse the repository at this point in the history
Check if BindingValue actually has a value before logging an error
  • Loading branch information
danwalmsley committed Jun 3, 2022
1 parent 5d360fa commit d18f979
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Avalonia.Base/Reactive/TypedBindingAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ public void OnNext(BindingValue<object?> value)
}
catch (InvalidCastException e)
{
var unwrappedValue = value.HasValue ? value.Value : null;

Logger.TryGet(LogEventLevel.Error, LogArea.Binding)?.Log(
_target,
"Binding produced invalid value for {$Property} ({$PropertyType}): {$Value} ({$ValueType})",
_property.Name,
_property.PropertyType,
value.Value,
value.Value?.GetType());
unwrappedValue,
unwrappedValue?.GetType());
PublishNext(BindingValue<T>.BindingError(e));
}
}
Expand Down

0 comments on commit d18f979

Please sign in to comment.