Skip to content

Commit

Permalink
Clarified SendExceptionInfoToWebhook is async
Browse files Browse the repository at this point in the history
  • Loading branch information
CPKreu committed Dec 13, 2023
1 parent 73ecd27 commit 0634755
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/PixiEditor/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected override void OnStartup(StartupEventArgs e)
{
try
{
CrashHelper.SendExceptionInfoToWebhook(exception);
CrashHelper.SendExceptionInfoToWebhook(exception, true);
}
finally
{
Expand Down
16 changes: 13 additions & 3 deletions src/PixiEditor/Helpers/CrashHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,24 @@ public static void AddExceptionMessage(StringBuilder builder, Exception e)
}
}

public static async Task SendExceptionInfoToWebhook(Exception e, [CallerFilePath] string filePath = "<unknown>", [CallerMemberName] string memberName = "<unknown>")
public static void SendExceptionInfoToWebhook(Exception e, bool wait = false,
[CallerFilePath] string filePath = "<unknown>", [CallerMemberName] string memberName = "<unknown>")
{
var task = Task.Run(() => SendExceptionInfoToWebhookAsync(e, filePath, memberName));
if (wait)
{
task.Wait();
}
}

public static async Task SendExceptionInfoToWebhookAsync(Exception e, [CallerFilePath] string filePath = "<unknown>", [CallerMemberName] string memberName = "<unknown>")
{
if (DebugViewModel.IsDebugBuild)
return;
await SendReportTextToWebhook(CrashReport.Generate(e), $"{filePath}; Method {memberName}");
await SendReportTextToWebhookAsync(CrashReport.Generate(e), $"{filePath}; Method {memberName}");
}

public static async Task SendReportTextToWebhook(CrashReport report, string catchLocation = null)
public static async Task SendReportTextToWebhookAsync(CrashReport report, string catchLocation = null)
{
string reportText = report.ReportText;
if (catchLocation is not null)
Expand Down
4 changes: 2 additions & 2 deletions src/PixiEditor/Models/AppExtensions/ExtensionLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void InitializeExtensions(ExtensionServices pixiEditorApi)
}
catch (Exception ex)
{
Task.Run(async () => await CrashHelper.SendExceptionInfoToWebhook(ex));
CrashHelper.SendExceptionInfoToWebhook(ex);
}
}

Expand Down Expand Up @@ -86,7 +86,7 @@ private void LoadExtension(string packageJsonPath)
catch (Exception ex)
{
//MessageBox.Show(new LocalizedString("ERROR_LOADING_PACKAGE", packageJsonPath), "ERROR");
Task.Run(async () => await CrashHelper.SendExceptionInfoToWebhook(ex));
CrashHelper.SendExceptionInfoToWebhook(ex);
}
}

Expand Down
14 changes: 0 additions & 14 deletions src/PixiEditor/Models/DataHolders/CrashFilePathInfo.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/PixiEditor/ViewModels/CrashReportViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public CrashReportViewModel(CrashReport report)
AttachDebuggerCommand = new(AttachDebugger);

if (!IsDebugBuild)
_ = CrashHelper.SendReportTextToWebhook(report);
_ = CrashHelper.SendReportTextToWebhookAsync(report);
}

public void RecoverDocuments(object args)
Expand Down
4 changes: 2 additions & 2 deletions src/PixiEditor/ViewModels/SubViewModels/Main/MiscViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ public MiscViewModel(ViewModelMain owner)
[Command.Basic("PixiEditor.Links.OpenRepository", "https://github.com/PixiEditor/PixiEditor", "REPOSITORY", "OPEN_REPOSITORY", IconPath = "Globe.png")]
[Command.Basic("PixiEditor.Links.OpenLicense", "https://github.com/PixiEditor/PixiEditor/blob/master/LICENSE", "LICENSE", "OPEN_LICENSE", IconPath = "Globe.png")]
[Command.Basic("PixiEditor.Links.OpenOtherLicenses", "https://pixieditor.net/docs/Third-party-licenses", "THIRD_PARTY_LICENSES", "OPEN_THIRD_PARTY_LICENSES", IconPath = "Globe.png")]
public static async Task OpenHyperlink(string url)
public static void OpenHyperlink(string url)
{
try
{
ProcessHelpers.ShellExecute(url);
}
catch (Exception e)
{
CrashHelper.SendExceptionInfoToWebhook(e);
NoticeDialog.Show(title: "Error", message: $"Couldn't open the address {url} in your default browser");
await CrashHelper.SendExceptionInfoToWebhook(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private async void ConditionalUPDATE()
}
catch (Exception e)
{
CrashHelper.SendExceptionInfoToWebhook(e);
CrashHelper.SendExceptionInfoToWebhookAsync(e);
NoticeDialog.Show("COULD_NOT_CHECK_FOR_UPDATES", "UPDATE_CHECK_FAILED");
}

Expand Down
2 changes: 1 addition & 1 deletion src/PixiEditor/Views/Dialogs/HelloTherePopup.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private async void HelloTherePopup_OnLoaded(object sender, RoutedEventArgs e)
{
IsFetchingNews = false;
FailedFetchingNews = true;
await CrashHelper.SendExceptionInfoToWebhook(ex);
await CrashHelper.SendExceptionInfoToWebhookAsync(ex);
}
}
}
2 changes: 1 addition & 1 deletion src/PixiEditor/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ MainWindow GetMainWindow()
}
catch (Exception e)
{
Task.Run(() => CrashHelper.SendExceptionInfoToWebhook(e)).Wait();
CrashHelper.SendExceptionInfoToWebhook(e, true);
throw;
}
}
Expand Down

0 comments on commit 0634755

Please sign in to comment.