add crash report startup logic
MODIFY
WalletWasabi.Gui/CommandLine/CrashReportCommand.cs
WalletWasabi.Gui/CommandLine/CrashReportCommand.cs
@@ -24,8 +24,16 @@ namespace WalletWasabi.Gui.CommandLine
private void ExceptionDecode(string exceptionString)
{
- var e = Guard.NotNullOrEmptyOrWhitespace(nameof(exceptionString), exceptionString);
- Global.CrashReportException = JsonConvert.DeserializeObject<SerializedException>(e);
+ var exS = Guard.NotNullOrEmptyOrWhitespace(nameof(exceptionString), exceptionString);
+
+ exS = exS.Replace("\\X0009", "\'")
+ .Replace("\\X0022", "\"")
+ .Replace("\\X000A", "\n")
+ .Replace("\\X000D", "\r")
+ .Replace("\\X0009", "\t")
+ .Replace("\\X0020", " ");
+
+ Global.CrashReportException = JsonConvert.DeserializeObject<SerializedException>(exS);
}
public Global Global { get; }
@@ -36,7 +44,7 @@ namespace WalletWasabi.Gui.CommandLine
{
Options.Parse(args);
- Global.CrashReportStartAttempt = Attempts;
+ Global.CrashReportStartAttempt = Convert.ToInt32(Attempts);
ExceptionDecode(ExceptionString);

ADD
WalletWasabi.Gui/CrashReporter/Helpers/StartCrashReporterHelper.cs
+using System.Reflection;
+using Avalonia;
+using System;
+using WalletWasabi.Logging;
+using Newtonsoft.Json;
+using WalletWasabi.Gui.CrashReporter.Models;
+using System.Diagnostics;
+
+namespace WalletWasabi.Gui.CrashReporter.Helpers
+{
+ public static class StartCrashReporterHelper
+ {
+ public static void Start(Exception e, int prevAttempts)
+ {
+ if (prevAttempts >= 5)
+ {
+ Logger.LogCritical("The crash helper has been called 5 times. Will not continue to avoid recursion errors.");
+ Environment.Exit(-1);
+ }
+
+ var jsonException = JsonConvert.SerializeObject(new SerializedException(e), Formatting.None)
+ .Replace("\'", "\\X0009")
+ .Replace("\"", "\\X0022")
+ .Replace("\n", "\\X000A")
+ .Replace("\r", "\\X000D")
+ .Replace("\t", "\\X0009")
+ .Replace(" ", "\\X0020");
+
+ var args = $"crashreport -attempt={prevAttempts + 1} -exception={jsonException}";
+
+ new Process()
+ {
+ StartInfo = new ProcessStartInfo()
+ {
+ FileName = Process.GetCurrentProcess().MainModule.FileName,
+ Arguments = $"{args}",
+ UseShellExecute = true
+ }
+ }.Start();
+
+ Environment.Exit(1);
+ return;
+ }
+ }
+}
\ No newline at end of file

MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -111,7 +111,7 @@ namespace WalletWasabi.Gui
private CancellationTokenSource StoppingCts { get; }
public SerializedException CrashReportException { get; set; }
- public string CrashReportStartAttempt { get; internal set; }
+ public int CrashReportStartAttempt { get; internal set; } = 0;
public async Task InitializeNoWalletAsync()
{

MODIFY
WalletWasabi.Gui/Program.cs
WalletWasabi.Gui/Program.cs
@@ -9,6 +9,7 @@ using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using WalletWasabi.Gui.CommandLine;
+using WalletWasabi.Gui.CrashReporter.Helpers;
using WalletWasabi.Gui.CrashReporter.Models;
using WalletWasabi.Gui.ViewModels;
using WalletWasabi.Logging;
@@ -87,6 +88,7 @@ namespace WalletWasabi.Gui
if (!(ex is OperationCanceledException))
{
Logger.LogCritical(ex);
+ StartCrashReporterHelper.Start(ex, Global.CrashReportStartAttempt);
}
await Global.DisposeAsync().ConfigureAwait(false);

add crash report startup logic