Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Flow.Launcher/Helper/ErrorReporting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Exception;
using Flow.Launcher.Infrastructure.Logger;
using NLog;

Check warning on line 8 in Flow.Launcher/Helper/ErrorReporting.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`NLog` is not a recognized word. (unrecognized-spelling)

namespace Flow.Launcher.Helper;

Expand All @@ -14,7 +14,7 @@
private static void Report(Exception e, bool silent = false, [CallerMemberName] string methodName = "UnHandledException")
{
var logger = LogManager.GetLogger(methodName);
logger.Fatal(ExceptionFormatter.FormatExcpetion(e));

Check warning on line 17 in Flow.Launcher/Helper/ErrorReporting.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Excpetion` is not a recognized word. (unrecognized-spelling)
if (silent) return;

// Workaround for issue https://github.com/Flow-Launcher/Flow.Launcher/issues/4016
Expand All @@ -23,8 +23,14 @@
// Many bug reports because users see the "Error report UI" after the crash with System.Runtime.InteropServices.COMException 0xD0000701 or 0x80263001.
// However, displaying this "Error report UI" during WPF crashes, especially when DWM composition is changing, is not ideal; some users reported it hangs for up to a minute before the it appears.
// This change modifies the behavior to log the exception instead of showing the "Error report UI".
if (ExceptionHelper.IsRecoverableDwmCompositionException(e)) return;

Check warning on line 26 in Flow.Launcher/Helper/ErrorReporting.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Dwm` is not a recognized word. (unrecognized-spelling)

// Workaround for a WPF issue where changing the Windows theme or accent color triggers
// SystemResources.InvalidateTreeResources, which tries to clone Color values stored in styles
// and fails with an InvalidCastException. This is a benign framework-level exception that
// does not affect Flow Launcher functionality, so we log it silently instead of showing the error dialog.
if (ExceptionHelper.IsRecoverableSystemResourceException(e)) return;

var reportWindow = new ReportWindow(e);
reportWindow.Show();
}
Expand Down
19 changes: 19 additions & 0 deletions Flow.Launcher/Helper/ExceptionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/// <summary>
/// Returns true if the exception is a recoverable DWM composition exception.
/// </summary>
internal static bool IsRecoverableDwmCompositionException(Exception exception)

Check warning on line 20 in Flow.Launcher/Helper/ExceptionHelper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Dwm` is not a recognized word. (unrecognized-spelling)

Check warning on line 20 in Flow.Launcher/Helper/ExceptionHelper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Dwm` is not a recognized word. (unrecognized-spelling)
{
if (exception is not COMException comException)
{
Expand All @@ -37,6 +37,25 @@
// Check for common DWM composition changed patterns in the stack trace
var stackTrace = comException.StackTrace;
return !string.IsNullOrEmpty(stackTrace) &&
stackTrace.Contains("DwmCompositionChanged", StringComparison.OrdinalIgnoreCase);

Check warning on line 40 in Flow.Launcher/Helper/ExceptionHelper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Dwm` is not a recognized word. (unrecognized-spelling)

Check warning on line 40 in Flow.Launcher/Helper/ExceptionHelper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Dwm` is not a recognized word. (unrecognized-spelling)
}

/// <summary>
/// Returns true if the exception is a recoverable WPF system resource invalidation exception
/// that occurs when Windows changes its theme or accent colors. This is a known WPF issue where
/// <c>Color</c> values stored in styles are incorrectly cloned during resource tree invalidation.
/// </summary>
internal static bool IsRecoverableSystemResourceException(Exception exception)
{
if (exception is not InvalidCastException)
{
return false;
}

// Check for the specific Color-to-Expression cast failure originating from WPF's
// SystemResources.InvalidateTreeResources, triggered by Windows theme/accent color changes.
var stackTrace = exception.StackTrace;
return !string.IsNullOrEmpty(stackTrace) &&
stackTrace.Contains("System.Windows.SystemResources.InvalidateTreeResources", StringComparison.Ordinal);
}
}
Loading