mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-11 07:15:31 +03:00
Ensure unhandled errors are handled in all configurations
This commit is contained in:
parent
5d2ac21185
commit
d935fb4a95
@ -9,6 +9,8 @@ public static class GtkEntryPoint
|
||||
{
|
||||
public static int Run(string[] args)
|
||||
{
|
||||
GLib.ExceptionManager.UnhandledException += UnhandledGtkException;
|
||||
|
||||
if (args.Length > 0 && args[0] is "cli" or "console")
|
||||
{
|
||||
return ConsoleEntryPoint.Run(args.Skip(1).ToArray(), new GtkImagesModule());
|
||||
@ -20,4 +22,16 @@ public static class GtkEntryPoint
|
||||
|
||||
return GuiEntryPoint.Run(args, new GtkImagesModule(), new GtkModule());
|
||||
}
|
||||
|
||||
private static void UnhandledGtkException(GLib.UnhandledExceptionArgs e)
|
||||
{
|
||||
if (e.IsTerminating)
|
||||
{
|
||||
Log.FatalException("An error occurred that caused the task to terminate.", e.ExceptionObject as Exception ?? new Exception());
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.ErrorException("An unhandled error occurred.", e.ExceptionObject as Exception ?? new Exception());
|
||||
}
|
||||
}
|
||||
}
|
@ -18,23 +18,6 @@ public class GtkEtoPlatform : EtoPlatform
|
||||
|
||||
public override bool IsGtk => true;
|
||||
|
||||
public override void InitializePlatform()
|
||||
{
|
||||
GLib.ExceptionManager.UnhandledException += UnhandledGtkException;
|
||||
}
|
||||
|
||||
private static void UnhandledGtkException(GLib.UnhandledExceptionArgs e)
|
||||
{
|
||||
if (e.IsTerminating)
|
||||
{
|
||||
Log.FatalException("An error occurred that caused the task to terminate.", e.ExceptionObject as Exception ?? new Exception());
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.ErrorException("An unhandled error occurred.", e.ExceptionObject as Exception ?? new Exception());
|
||||
}
|
||||
}
|
||||
|
||||
public override Application CreateApplication()
|
||||
{
|
||||
var application = new Application(Platforms.Gtk);
|
||||
|
@ -9,6 +9,16 @@ public static class MacEntryPoint
|
||||
{
|
||||
public static int Run(string[] args)
|
||||
{
|
||||
Runtime.MarshalManagedException += (_, eventArgs) =>
|
||||
{
|
||||
Log.ErrorException("Marshalling managed exception", eventArgs.Exception);
|
||||
eventArgs.ExceptionMode = MarshalManagedExceptionMode.ThrowObjectiveCException;
|
||||
};
|
||||
Runtime.MarshalObjectiveCException += (_, eventArgs) =>
|
||||
{
|
||||
Log.Error($"Marshalling ObjC exception: {eventArgs.Exception.Description}");
|
||||
};
|
||||
|
||||
if (args.Length > 0 && args[0] is "cli" or "console")
|
||||
{
|
||||
return ConsoleEntryPoint.Run(args.Skip(1).ToArray(), new MacImagesModule());
|
||||
|
@ -19,16 +19,6 @@ public class MacEtoPlatform : EtoPlatform
|
||||
// into a foreground process once we know we're not in worker or console mode. This ensures workers don't have
|
||||
// a chance to show in the dock.
|
||||
MacProcessHelper.TransformThisProcessToForeground();
|
||||
|
||||
Runtime.MarshalManagedException += (_, eventArgs) =>
|
||||
{
|
||||
Log.ErrorException("Marshalling managed exception", eventArgs.Exception);
|
||||
eventArgs.ExceptionMode = MarshalManagedExceptionMode.ThrowObjectiveCException;
|
||||
};
|
||||
Runtime.MarshalObjectiveCException += (_, eventArgs) =>
|
||||
{
|
||||
Log.Error($"Marshalling ObjC exception: {eventArgs.Exception.Description}");
|
||||
};
|
||||
}
|
||||
|
||||
public override Application CreateApplication()
|
||||
|
@ -26,6 +26,7 @@ public static class ConsoleEntryPoint
|
||||
new CommonModule(), imageModule, new ConsoleModule(options), new RecoveryModule(), new ContextModule());
|
||||
|
||||
Paths.ClearTemp();
|
||||
TaskScheduler.UnobservedTaskException += UnhandledTaskException;
|
||||
|
||||
// Start a pending worker process
|
||||
container.Resolve<IWorkerFactory>().Init(
|
||||
@ -38,4 +39,10 @@ public static class ConsoleEntryPoint
|
||||
|
||||
return ((ConsoleErrorOutput) container.Resolve<ErrorOutput>()).HasError ? 1 : 0;
|
||||
}
|
||||
|
||||
private static void UnhandledTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
|
||||
{
|
||||
Log.FatalException("An error occurred that caused the task to terminate.", e.Exception);
|
||||
e.SetObserved();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user