Skip to content

Commit

Permalink
chore: improve error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Dec 6, 2023
1 parent 01f8223 commit a436cf5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Uno.UI.Runtime.Skia.Wpf/Input/WpfKeyboardInputSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,20 @@ private static uint GetScanCode(KeyEventArgs args)
{
try
{
return (uint)((int)(typeof(KeyEventArgs).GetProperty("ScanCode", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(args) ?? 0));
if (typeof(KeyEventArgs).GetProperty("ScanCode", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) is { } propertyInfo)

Check warning on line 99 in src/Uno.UI.Runtime.Skia.Wpf/Input/WpfKeyboardInputSource.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Uno.UI.Runtime.Skia.Wpf/Input/WpfKeyboardInputSource.cs#L99

Make sure that this accessibility bypass is safe here.
{
return (uint)(int)propertyInfo.GetValue(args)!;
}
else
{
throw new PlatformNotSupportedException("Unable to get the ScanCode property from WPF. This likely means this WPF version is not compatible with Uno Platform, contact the developers for more information.");
}
}
catch (Exception e)
{
if (typeof(WpfKeyboardInputSource).Log().IsEnabled(LogLevel.Error))
{
typeof(WpfKeyboardInputSource).Log().LogError("Couldn't get ScanCode from WPF KeyEventArgs.", e);
typeof(WpfKeyboardInputSource).Log().LogError("Unable to get ScanCode from WPF KeyEventArgs.", e);
}

throw;
Expand Down

0 comments on commit a436cf5

Please sign in to comment.