Skip to content
Merged
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
9 changes: 9 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,8 +14,17 @@
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
// The crash occurs in PresentationFramework.dll, not necessarily when the Runner UI is visible, originating from this line:
// https://github.com/dotnet/wpf/blob/3439f20fb8c685af6d9247e8fd2978cac42e74ac/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/WindowChromeWorker.cs#L1005
// 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)

var reportWindow = new ReportWindow(e);
reportWindow.Show();
}
Expand Down
42 changes: 42 additions & 0 deletions Flow.Launcher/Helper/ExceptionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// This is a direct copy of the file at https://github.com/microsoft/PowerToys/blob/main/src/modules/launcher/PowerLauncher/Helper/ExceptionHelper.cs and adapted for flow.

using System;
using System.Runtime.InteropServices;

namespace Flow.Launcher.Helper;

internal static class ExceptionHelper
{
private const string PresentationFrameworkExceptionSource = "PresentationFramework";

private const int DWM_E_COMPOSITIONDISABLED = unchecked((int)0x80263001);

// HRESULT for NT STATUS STATUS_MESSAGE_LOST (0xC0000701 | 0x10000000 == 0xD0000701)
private const int STATUS_MESSAGE_LOST_HR = unchecked((int)0xD0000701);

/// <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)
{
return false;
}

if (comException.HResult is DWM_E_COMPOSITIONDISABLED)
{
return true;
}

if (comException.HResult is STATUS_MESSAGE_LOST_HR && comException.Source == PresentationFrameworkExceptionSource)
{
return true;
}

// 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)
}
}
Loading