Skip to content

Commit 429399a

Browse files
authored
Merge pull request #2850 from DGP-Studio/develop
2 parents e2617a7 + 826dd8e commit 429399a

File tree

20 files changed

+1555
-343
lines changed

20 files changed

+1555
-343
lines changed

src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/ExceptionHandlingSupport.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,25 @@ public static void Initialize(IServiceProvider serviceProvider, Application app)
2222
serviceProvider.GetRequiredService<ExceptionHandlingSupport>().Attach(app);
2323
}
2424

25+
/// <summary>
26+
/// Kill the current process if the exception is or has a DbException.
27+
/// As this method does not throw, it should only be used in catch blocks
28+
/// </summary>
29+
/// <param name="exception">Incoming exception</param>
30+
/// <returns>Unwrapped DbException or original exception</returns>
2531
[StackTraceHidden]
26-
public static void KillProcessOnDbException(Exception exception)
32+
public static Exception KillProcessOnDbExceptionNoThrow(Exception exception)
2733
{
28-
ExceptionDispatchInfo dispatch = ExceptionDispatchInfo.Capture(exception);
29-
30-
switch (dispatch.SourceException)
34+
return exception switch
3135
{
32-
case DbException dbException:
33-
throw KillProcessOnDbException(dbException);
34-
case DbUpdateException { InnerException: DbException dbException2 }:
35-
throw KillProcessOnDbException(dbException2);
36-
default:
37-
// In case it's not a DbException, we should preserve the original stack trace
38-
dispatch.Throw();
39-
break;
40-
}
36+
DbException dbException => KillProcessOnDbException(dbException),
37+
DbUpdateException { InnerException: DbException dbException2 } => KillProcessOnDbException(dbException2),
38+
_ => exception,
39+
};
4140
}
4241

4342
[StackTraceHidden]
44-
public static DbException KillProcessOnDbException(DbException exception)
43+
private static DbException KillProcessOnDbException(DbException exception)
4544
{
4645
HutaoNative.Instance.ShowErrorMessage("Warning | 警告", exception.Message);
4746
Process.GetCurrentProcess().Kill();
@@ -60,7 +59,7 @@ private static void OnAppUnhandledException(object? sender, Microsoft.UI.Xaml.Un
6059
Debugger.Break();
6160
XamlApplicationLifetime.Exiting = true;
6261

63-
KillProcessOnDbException(e.Exception);
62+
KillProcessOnDbExceptionNoThrow(e.Exception);
6463

6564
// https://github.com/getsentry/sentry-dotnet/blob/main/src/Sentry/Integrations/WinUIUnhandledExceptionIntegration.cs
6665
exception.SetSentryMechanism("Microsoft.UI.Xaml.UnhandledException", handled: false);

src/Snap.Hutao/Snap.Hutao/Core/Threading/TaskExtension.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static async void SafeForget(this Task task)
1919
}
2020
catch (Exception ex)
2121
{
22-
ExceptionHandlingSupport.KillProcessOnDbException(ex);
22+
ExceptionHandlingSupport.KillProcessOnDbExceptionNoThrow(ex);
2323
ex.SetSentryMechanism("TaskExtension.SafeForget", handled: true);
2424
SentrySdk.CaptureException(ex);
2525
}
@@ -37,7 +37,7 @@ public static async void SafeForget(this ValueTask task)
3737
}
3838
catch (Exception ex)
3939
{
40-
ExceptionHandlingSupport.KillProcessOnDbException(ex);
40+
ExceptionHandlingSupport.KillProcessOnDbExceptionNoThrow(ex);
4141
ex.SetSentryMechanism("TaskExtension.SafeForget", handled: true);
4242
SentrySdk.CaptureException(ex);
4343
}

src/Snap.Hutao/Snap.Hutao/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<Identity
1414
Name="60568DGPStudio.SnapHutao"
1515
Publisher="CN=35C8E923-85DF-49A7-9172-B39DC6312C52"
16-
Version="1.15.6.0" />
16+
Version="1.15.7.0" />
1717

1818
<Properties>
1919
<DisplayName>Snap Hutao</DisplayName>

src/Snap.Hutao/Snap.Hutao/Package.development.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<Identity
1414
Name="60568DGPStudio.SnapHutaoDev"
1515
Publisher="CN=35C8E923-85DF-49A7-9172-B39DC6312C52"
16-
Version="1.15.6.0" />
16+
Version="1.15.7.0" />
1717

1818
<Properties>
1919
<DisplayName>Snap Hutao Dev</DisplayName>

src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.de.resx

Lines changed: 110 additions & 23 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)