Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Error Collection #603

Merged
merged 36 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8732850
Initial implementation for Sentry SDK
bagusnl Nov 8, 2024
d0a3211
add new global constant
Cryotechnic Nov 8, 2024
a1de6fc
add toggle in settings for sentrysdk usage
Cryotechnic Nov 8, 2024
2e72ff9
install sentry in helper
Cryotechnic Nov 8, 2024
aa24ff1
wrap exception calls in global exception handler
Cryotechnic Nov 8, 2024
ca94813
remove unecessary init calls in main func
Cryotechnic Nov 8, 2024
a0de474
Merge remote-tracking branch 'https/cry0/sentry-integration-improveme…
bagusnl Nov 9, 2024
ea45a30
Refactor
bagusnl Nov 9, 2024
fb444ae
Catch ImageLoaderHelper download exceptions
bagusnl Nov 9, 2024
105da53
Refactor Sentry toggle
bagusnl Nov 9, 2024
421eefa
Make sure to not send PII
bagusnl Nov 9, 2024
24a6123
Add dedup and attachment flags
bagusnl Nov 9, 2024
ff07860
weeeeeeeeeeeee
bagusnl Nov 9, 2024
115ab82
Pipe exceptions coming from EventsHandler.SendException
bagusnl Nov 9, 2024
101f937
add sentry logging to some exceptions
Cryotechnic Nov 11, 2024
95a23b6
finish adding sentry logging to base project
Cryotechnic Nov 11, 2024
66f4278
fixed typo in exception message
Cryotechnic Nov 11, 2024
5f3bb9c
Update base
bagusnl Nov 11, 2024
4aca619
Remove Sentry log upload on TCE/OCE
bagusnl Nov 11, 2024
a11cd74
Add more catcher for SentryHelper
bagusnl Nov 11, 2024
1fda0ce
Documentations
bagusnl Nov 11, 2024
41950e0
Switch handler to async on InstallmanagerBase.ApplyDeleteFileActionAsync
bagusnl Nov 11, 2024
325e4d7
[skip ci] Update Privacy Policy
bagusnl Nov 11, 2024
94deba0
Some improvements
bagusnl Nov 12, 2024
30ab4ae
Reattach exception redirection event when enabled from settings
bagusnl Nov 12, 2024
6180077
Update base
bagusnl Nov 12, 2024
2391610
Switch to GlitchTip provider
bagusnl Nov 14, 2024
d5a0107
Separate log file by time of launch
bagusnl Nov 15, 2024
c8e6630
Improve SentryEventProcessor.cs
bagusnl Nov 15, 2024
2a10d9a
Miss one catcher there
bagusnl Nov 16, 2024
2baa33d
Remove Sentry from main app and pkg lock update
bagusnl Nov 16, 2024
dfa2d43
Sentry improvements
bagusnl Nov 16, 2024
653ed45
Exception Handler improvements
bagusnl Nov 16, 2024
1f324fc
[skip ci] Deduplicate ExceptionHandlerAsync
bagusnl Nov 16, 2024
c4a9465
[skip ci] Clean-up initializer
bagusnl Nov 16, 2024
6722a1c
[skip ci] MSBuild Integration
bagusnl Nov 16, 2024
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
11 changes: 9 additions & 2 deletions CollapseLauncher/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CollapseLauncher.Helper;
using CollapseLauncher.Helper.Image;
using Hi3Helper;
using Hi3Helper.SentryHelper;
using Hi3Helper.Shared.Region;
using Microsoft.UI;
using Microsoft.UI.Xaml;
Expand Down Expand Up @@ -51,9 +52,14 @@ public App()
UnhandledException += static (sender, e) =>
{
LogWriteLine($"[XAML_OTHER] Sender: {sender}\r\n{e!.Exception} {e.Exception!.InnerException}", LogType.Error, true);
#if !DEBUG
var ex = e.Exception;
if (ex != null)
{
SentryHelper.ExceptionHandler(ex, SentryHelper.ExceptionType.UnhandledXaml);
}
#if !DEBUG
MainEntryPoint.SpawnFatalErrorConsole(e!.Exception);
#endif
#endif
};
}

Expand Down Expand Up @@ -133,6 +139,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
{
LogWriteLine($"FATAL ERROR ON APP INITIALIZER LEVEL!!!\r\n{ex}", LogType.Error, true);
LogWriteLine("\r\nIf this is not intended, please report it to: https://github.com/CollapseLauncher/Collapse/issues\r\nPress any key to exit...");
SentryHelper.ExceptionHandler(ex, SentryHelper.ExceptionType.UnhandledOther);
//Console.ReadLine();
throw;
}
Expand Down
9 changes: 8 additions & 1 deletion CollapseLauncher/Classes/EventsManagement/EventsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text.Json.Serialization;
using Windows.Foundation;
using Windows.Networking.Connectivity;
using Hi3Helper.SentryHelper;
using static CollapseLauncher.InnerLauncherConfig;
using static Hi3Helper.Locale;
using static Hi3Helper.Shared.Region.LauncherConfig;
Expand Down Expand Up @@ -133,11 +134,17 @@ internal static class ErrorSender
public static ErrorType ExceptionType;
public static string ExceptionTitle;
public static string ExceptionSubtitle;
public static void SendException(Exception e, ErrorType eT = ErrorType.Unhandled) => invoker!.SendException(e, eT);

public static void SendException(Exception e, ErrorType eT = ErrorType.Unhandled)
{
SentryHelper.ExceptionHandler(e, eT == ErrorType.Unhandled ? SentryHelper.ExceptionType.UnhandledOther : SentryHelper.ExceptionType.Handled);
invoker!.SendException(e, eT);
}
public static void SendWarning(Exception e, ErrorType eT = ErrorType.Warning) =>
invoker!.SendException(e, eT);
public static void SendExceptionWithoutPage(Exception e, ErrorType eT = ErrorType.Unhandled)
{
SentryHelper.ExceptionHandler(e, eT == ErrorType.Unhandled ? SentryHelper.ExceptionType.UnhandledOther : SentryHelper.ExceptionType.Handled);
ExceptionContent = e!.ToString();
ExceptionType = eT;
SetPageTitle(eT);
Expand Down
2 changes: 2 additions & 0 deletions CollapseLauncher/Classes/Extension/UIElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Runtime.CompilerServices;
using Windows.UI;
using Windows.UI.Text;
using Hi3Helper.SentryHelper;

namespace CollapseLauncher.Extension
{
Expand Down Expand Up @@ -921,6 +922,7 @@ void AttachShadow(FrameworkElement thisElement, bool innerMask, Vector3? _offset
}
catch (Exception ex)
{
SentryHelper.ExceptionHandler(ex, SentryHelper.ExceptionType.UnhandledXaml);
Logger.LogWriteLine($"Failed while attaching shadow to an element\r\n{ex}", LogType.Warning, true);
}
}
Expand Down
4 changes: 4 additions & 0 deletions CollapseLauncher/Classes/FileDialogCOM/FileDialogNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Hi3Helper.SentryHelper;

namespace CollapseLauncher.FileDialogCOM
{
Expand Down Expand Up @@ -79,6 +80,7 @@ private static ValueTask<object> GetPickerOpenTask<T>(object defaultValue, Dicti
}
catch (COMException ex)
{
SentryHelper.ExceptionHandler(ex, SentryHelper.ExceptionType.UnhandledOther);
Logger.LogWriteLine($"COM Exception: {ex}", LogType.Error, true);
return new ValueTask<object>(defaultValue);
}
Expand Down Expand Up @@ -117,6 +119,7 @@ private static ValueTask<string> GetPickerSaveTask<T>(string defaultValue, Dicti
}
catch (COMException ex)
{
SentryHelper.ExceptionHandler(ex, SentryHelper.ExceptionType.UnhandledOther);
Logger.LogWriteLine($"COM Exception: {ex}", LogType.Error, true);
return new ValueTask<string>(defaultValue);
}
Expand Down Expand Up @@ -187,6 +190,7 @@ private static string COMPtrToUnicodeString(IntPtr ptr)
}
catch (Exception e)
{
SentryHelper.ExceptionHandler(e, SentryHelper.ExceptionType.UnhandledOther);
Logger.LogWriteLine($"Error while marshalling COM Pointer {ptr} to string!\r\n{e}");
throw;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Hi3Helper.SentryHelper;
using static Hi3Helper.Logger;

namespace CollapseLauncher.GamePlaytime
Expand Down Expand Up @@ -125,6 +126,7 @@ public static CollapsePlaytime Load(RegistryKey root, int hashID,
}
catch (Exception ex)
{
SentryHelper.ExceptionHandler(ex, SentryHelper.ExceptionType.UnhandledOther);
LogWriteLine($"Failed while reading playtime.\r\n{ex}", LogType.Error, true);
}
finally
Expand Down Expand Up @@ -170,6 +172,7 @@ public void Save(bool forceUpdateDb = false)
}
catch (Exception ex)
{
SentryHelper.ExceptionHandler(ex, SentryHelper.ExceptionType.UnhandledOther);
LogWriteLine($"Failed to save playtime!\r\n{ex}", LogType.Error, true);
}
}
Expand Down Expand Up @@ -348,6 +351,7 @@ public void AddMinute()
}
catch (Exception ex)
{
await SentryHelper.ExceptionHandlerAsync(ex, SentryHelper.ExceptionType.UnhandledOther);
LogWriteLine($"[CollapsePlaytime::DbSync] Failed when trying to do sync operation\r\n{ex}",
LogType.Error, true);
return (false, null);
Expand All @@ -364,16 +368,18 @@ private async Task UpdatePlaytime_Database_Push(string jsonData, double totalTim
try
{
var unixStamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
await DbHandler.StoreKeyValue(KeyPlaytimeJson, jsonData);
await DbHandler.StoreKeyValue(KeyTotalTime, totalTime.ToString(CultureInfo.InvariantCulture));
await DbHandler.StoreKeyValue(KeyLastPlayed, lastPlayed != null ? lastPlayed.Value.ToString(CultureInfo.InvariantCulture) : "null");
await DbHandler.StoreKeyValue(KeyLastUpdated, unixStamp.ToString());
await DbHandler.StoreKeyValue(KeyPlaytimeJson, jsonData, true);
await DbHandler.StoreKeyValue(KeyTotalTime, totalTime.ToString(CultureInfo.InvariantCulture), true);
await DbHandler.StoreKeyValue(KeyLastPlayed, lastPlayed != null ? lastPlayed.Value.ToString(CultureInfo.InvariantCulture) : "null", true);
await DbHandler.StoreKeyValue(KeyLastUpdated, unixStamp.ToString(), true);
DbConfig.SetAndSaveValue(KeyLastUpdated, unixStamp);
_unixStampDb = Convert.ToInt32(unixStamp);
LastDbUpdate = curDateTime;
LogWriteLine("[CollapsePlaytime::UpdatePlaytime_Database_Push()] Successfully uploaded playtime data to database!", LogType.Scheme, true);
}
catch (Exception e)
{
await SentryHelper.ExceptionHandlerAsync(e, SentryHelper.ExceptionType.UnhandledOther);
LogWriteLine($"Failed when syncing Playtime to DB!\r\n{e}", LogType.Error, true);
}
finally
Expand All @@ -390,18 +396,20 @@ private async Task UpdatePlaytime_Database_Pull()
{
_isDbPulling = true;

_jsonDataDb = await DbHandler.QueryKey(KeyPlaytimeJson);
_jsonDataDb = await DbHandler.QueryKey(KeyPlaytimeJson, true);

var totalTimeDbStr = await DbHandler.QueryKey(KeyTotalTime);
var totalTimeDbStr = await DbHandler.QueryKey(KeyTotalTime, true);
_totalTimeDb = string.IsNullOrEmpty(totalTimeDbStr) ? null : Convert.ToDouble(totalTimeDbStr, CultureInfo.InvariantCulture);

var lpDb = await DbHandler.QueryKey(KeyLastPlayed);
var lpDb = await DbHandler.QueryKey(KeyLastPlayed, true);
_lastPlayedDb = !string.IsNullOrEmpty(lpDb) && !lpDb.Contains("null") ? Convert.ToDouble(lpDb, CultureInfo.InvariantCulture) : null; // if Db data is null, return null

_isDbPullSuccess = true;
LogWriteLine("[CollapsePlaytime::UpdatePlaytime_Database_Pull()] Successfully pulled data from database!", LogType.Scheme, true);
}
catch (Exception e)
{
await SentryHelper.ExceptionHandlerAsync(e, SentryHelper.ExceptionType.UnhandledOther);
LogWriteLine($"Failed when syncing Playtime to DB!\r\n{e}", LogType.Error, true);
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ internal class ImportExportBase
}
catch (Exception ex)
{
// Gets caught by the calling method
return ex;
}

Expand Down Expand Up @@ -190,6 +191,7 @@ private void ReadV3Values(Stream fs, string? gameBasePath)
}
catch (Exception ex)
{
// Gets caught by calling method
return ex;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
using Hi3Helper.SentryHelper;

#nullable enable
namespace CollapseLauncher.GameSettings.Base
Expand Down Expand Up @@ -319,6 +320,7 @@ public static T LoadWithMagic(byte[] magic, SettingsGameVersionManager versionMa
}
catch (Exception ex)
{
SentryHelper.ExceptionHandler(ex, SentryHelper.ExceptionType.UnhandledOther);
Logger.LogWriteLine($"Failed to parse MagicNodeBaseValues settings\r\n{ex}", LogType.Error, true);
return DefaultValue(magic, versionManager, typeInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ public void Save()
catch (Exception ex)
{
LogWriteLine($"Failed to save {_ValueName}!\r\n{ex}", LogType.Error, true);
ErrorSender.SendException(new Exception("Failed to save Genshin settings, please report them to GitHub issues!", ex));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public override void Save()
catch (Exception ex)
{
LogWriteLine($"Failed to save Genshin Impact ScreenManager Values!\r\n{ex}", LogType.Error, true);
ErrorSender.SendException(new Exception("Failed to save Genshin Impact ScreenManager Values!", ex));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Hi3Helper.EncTool;
using Microsoft.Win32;
using System;
using Hi3Helper.SentryHelper;
using static CollapseLauncher.GameSettings.Base.SettingsBase;
using static Hi3Helper.Logger;

Expand Down Expand Up @@ -72,6 +73,7 @@ public void Save()
catch (Exception ex)
{
LogWriteLine($"Failed to save {_ValueName}!\r\n{ex}", LogType.Error, true);
SentryHelper.ExceptionHandler(new Exception($"Failed to save {_ValueName}!", ex), SentryHelper.ExceptionType.UnhandledOther);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Hi3Helper.EncTool;
using Microsoft.Win32;
using System;
using Hi3Helper.SentryHelper;
using static CollapseLauncher.GameSettings.Base.SettingsBase;
using static Hi3Helper.Logger;

Expand Down Expand Up @@ -72,6 +73,7 @@ public void Save()
catch (Exception ex)
{
LogWriteLine($"Failed to save {_ValueName}!\r\n{ex}", LogType.Error, true);
SentryHelper.ExceptionHandler(new Exception($"Failed to save {_ValueName}!", ex), SentryHelper.ExceptionType.UnhandledOther);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Hi3Helper;
using Microsoft.Win32;
using System;
using Hi3Helper.SentryHelper;
using static CollapseLauncher.GameSettings.Base.SettingsBase;
using static Hi3Helper.Logger;

Expand Down Expand Up @@ -76,6 +77,7 @@ public void Save()
catch (Exception ex)
{
LogWriteLine($"Failed to save {_ValueName}!\r\n{ex}", LogType.Error, true);
SentryHelper.ExceptionHandler(new Exception($"Failed to save {_ValueName}!", ex), SentryHelper.ExceptionType.UnhandledOther);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Text;
using System.Text.Json.Serialization;
using Hi3Helper.SentryHelper;
using static CollapseLauncher.GameSettings.Base.SettingsBase;
using static Hi3Helper.Data.ConverterTool;
using static Hi3Helper.Logger;
Expand Down Expand Up @@ -223,6 +224,7 @@ public void Save()
catch (Exception ex)
{
LogWriteLine($"Failed to save {_ValueName}!\r\n{ex}", LogType.Error, true);
SentryHelper.ExceptionHandler(new Exception($"Failed to save {_ValueName}!", ex), SentryHelper.ExceptionType.UnhandledOther);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Win32;
using System;
using System.Text;
using Hi3Helper.SentryHelper;
using static CollapseLauncher.GameSettings.Base.SettingsBase;
using static Hi3Helper.Logger;

Expand Down Expand Up @@ -115,6 +116,7 @@ public void Save()
catch (Exception ex)
{
LogWriteLine($"Failed to save {_ValueName}!\r\n{ex}", LogType.Error, true);
SentryHelper.ExceptionHandler(new Exception($"Failed to save {_ValueName}!", ex), SentryHelper.ExceptionType.UnhandledOther);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CollapseLauncher.Interfaces;
using Hi3Helper;
using Hi3Helper.EncTool;
using Hi3Helper.SentryHelper;
using Microsoft.Win32;
using System;
using System.Text;
Expand Down Expand Up @@ -224,6 +225,7 @@ public void Save()
}
catch (Exception ex)
{
SentryHelper.ExceptionHandler(ex, SentryHelper.ExceptionType.UnhandledOther);
LogWriteLine($"Failed to save {_ValueName}!\r\n{ex}", LogType.Error, true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Hi3Helper;
using Microsoft.Win32;
using System;
using Hi3Helper.SentryHelper;
using static CollapseLauncher.GameSettings.Base.SettingsBase;
using static Hi3Helper.Logger;

Expand Down Expand Up @@ -73,6 +74,7 @@ public void Save()
catch (Exception ex)
{
LogWriteLine($"Failed to save {_ValueName}!\r\n{ex}", LogType.Error, true);
SentryHelper.ExceptionHandler(new Exception($"Failed to save {_ValueName}!", ex), SentryHelper.ExceptionType.UnhandledOther);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Drawing;
using System.Text;
using System.Text.Json.Serialization;
using Hi3Helper.SentryHelper;
using static CollapseLauncher.GameSettings.Base.SettingsBase;
using static Hi3Helper.Logger;

Expand Down Expand Up @@ -141,6 +142,7 @@ public override void Save()
catch (Exception ex)
{
LogWriteLine($"Failed to save {_ValueName}!\r\n{ex}", LogType.Error, true);
SentryHelper.ExceptionHandler(new Exception($"Failed to save {_ValueName}!", ex), SentryHelper.ExceptionType.UnhandledOther);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Hi3Helper.EncTool;
using Microsoft.Win32;
using System;
using Hi3Helper.SentryHelper;
using static CollapseLauncher.GameSettings.Base.SettingsBase;
using static Hi3Helper.Logger;

Expand Down Expand Up @@ -69,6 +70,7 @@ public void Save()
catch (Exception ex)
{
LogWriteLine($"Failed to save {_ValueName}!\r\n{ex}", LogType.Error, true);
SentryHelper.ExceptionHandler(new Exception($"Failed to save {_ValueName}!", ex), SentryHelper.ExceptionType.UnhandledOther);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Win32;
using System;
using System.Text;
using Hi3Helper.SentryHelper;
using static CollapseLauncher.GameSettings.Base.SettingsBase;
using static Hi3Helper.Logger;

Expand Down Expand Up @@ -98,6 +99,7 @@ public void Save()
catch (Exception ex)
{
LogWriteLine($"Failed to save {_ValueName}!\r\n{ex}", LogType.Error, true);
SentryHelper.ExceptionHandler(new Exception($"Failed to save {_ValueName}!", ex), SentryHelper.ExceptionType.UnhandledOther);
}

}
Expand Down
Loading