Skip to content

Commit

Permalink
Fix Grid Bot Issues (#91)
Browse files Browse the repository at this point in the history
* Add missing arg to crash handler wrapper

* Do better

* Do not exit?

* Is meant to write settings to vault, doesn't work though

* Fix build issue
  • Loading branch information
jf-06 authored Jul 13, 2022
1 parent 42dcd52 commit 2ff1459
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion MFDLabs.Grid.Bot/CrashHandlerWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
internal static class CrashHandlerWrapper
{
public static void Upload(System.Exception ex) => MFDLabs.Grid.Bot.Utility.CrashHandler.Upload(ex);
public static void Upload(System.Exception ex, bool overrideSystemWhenExitingCrashHandler = false) => MFDLabs.Grid.Bot.Utility.CrashHandler.Upload(ex, overrideSystemWhenExitingCrashHandler);
}
}
22 changes: 18 additions & 4 deletions MFDLabs.Grid.Bot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void Main(string[] args)
global::System.Console.ResetColor();

if (AssemblyIsLoaded("MFDLabs.Backtrace") && AssemblyIsLoaded("MFDLabs.GridSettings") && AssemblyIsLoaded("MFDLabs.GridUtility"))
global::MFDLabs.Grid.Bot.CrashHandlerWrapper.Upload(new global::System.ApplicationException(GetBadConfigurationError()));
global::MFDLabs.Grid.Bot.CrashHandlerWrapper.Upload(new global::System.ApplicationException(GetBadConfigurationError()), true);

return;
}
Expand All @@ -55,6 +55,8 @@ public static void Main(string[] args)
(e.ExceptionObject as global::System.Exception)?.Message
);
global::System.Console.ResetColor();
global::System.Console.WriteLine("Press any key to exit...");
global::System.Console.ReadKey(true);
global::System.Environment.Exit(1);
return;
}
Expand All @@ -68,12 +70,24 @@ public static void Main(string[] args)
global::System.Console.ResetColor();

if (AssemblyIsLoaded("MFDLabs.Backtrace") && AssemblyIsLoaded("MFDLabs.GridSettings") && AssemblyIsLoaded("MFDLabs.GridUtility"))
global::MFDLabs.Grid.Bot.CrashHandlerWrapper.Upload(e.ExceptionObject as global::System.Exception);
global::MFDLabs.Grid.Bot.CrashHandlerWrapper.Upload(e.ExceptionObject as global::System.Exception, true);

global::MFDLabs.Grid.Bot.Runner.OnGlobalException(e.ExceptionObject as global::System.Exception);

if (e.ExceptionObject is global::System.InvalidOperationException)
global::System.Environment.Exit(1);
if (e.ExceptionObject is global::System.AggregateException aggregate)
{
if (global::System.Linq.Enumerable.Any(
global::System.Linq.Enumerable.Where(
aggregate.InnerExceptions,
x => x is global::System.InvalidOperationException
)
))
{
global::System.Console.WriteLine("Press any key to exit...");
global::System.Console.ReadKey(true);
global::System.Environment.Exit(1);
}
}
};

global::MFDLabs.Grid.Bot.Runner.Invoke(args);
Expand Down
10 changes: 10 additions & 0 deletions MFDLabs.Grid.Bot/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ public static void Invoke(string[] args)
$"opened with file name '{SystemGlobal.CurrentProcess.ProcessName}' at path " +
$"'{Directory.GetCurrentDirectory()}' (version {SystemGlobal.AssemblyVersion})."
);

if (args.Contains("--write-settings"))
{
Logger.Singleton.Warning("Writing settings instead of actually launching.");

global::MFDLabs.Grid.Bot.Properties.Settings.Default.Save();

Environment.Exit(0);
return;
}

Logger.Singleton.Debug(
"Process '{0}' opened with file name '{1}' at path '{2}' (version {3}).",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public static void RespondEphemeral(
MessageComponent component = null,
Embed embed = null,
RequestOptions options = null
) => command.RespondEphemeralAsync(text, pingUser, embeds, isTts, component, embed, options).Sync();
) => command.RespondEphemeralAsync(text, pingUser, embeds, isTts, component, embed, options).Wait();

public static void RespondEphemeralPing(
this SocketCommandBase command,
Expand All @@ -310,7 +310,7 @@ public static void RespondEphemeralPing(
MessageComponent component = null,
Embed embed = null,
RequestOptions options = null
) => command.RespondEphemeralPingAsync(text, embeds, isTts, component, embed, options).Sync();
) => command.RespondEphemeralPingAsync(text, embeds, isTts, component, embed, options).Wait();

public static void RespondPublic(
this SocketCommandBase command,
Expand All @@ -321,7 +321,7 @@ public static void RespondPublic(
MessageComponent component = null,
Embed embed = null,
RequestOptions options = null
) => command.RespondPublicAsync(text, pingUser, embeds, isTts, component, embed, options).Sync();
) => command.RespondPublicAsync(text, pingUser, embeds, isTts, component, embed, options).Wait();

public static void RespondPublicPing(
this SocketCommandBase command,
Expand All @@ -331,7 +331,7 @@ public static void RespondPublicPing(
MessageComponent component = null,
Embed embed = null,
RequestOptions options = null
) => command.RespondPublicPingAsync(text, embeds, isTts, component, embed, options).Sync();
) => command.RespondPublicPingAsync(text, embeds, isTts, component, embed, options).Wait();

public static async Task<bool> RejectIfNotAdminAsync(this SocketCommandBase cmd)
=> await AdminUtility.RejectIfNotAdminAsync(cmd);
Expand Down
6 changes: 5 additions & 1 deletion Shared/MFDLabs.GridUtility/CrashHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ public static void Upload(System.Exception ex, bool overrideSystemWhenExitingCra
if (ex == null)
return;

var traceBack = global::MFDLabs.ErrorHandling.Extensions.ExceptionExtensions.ToDetailedString(
new global::System.Exception("Crash Handler call traceback.", ex)
);

global::System.Threading.ThreadPool.QueueUserWorkItem(s =>
{
try
{
System.Console.WriteLine(global::MFDLabs.Grid.Bot.Properties.Resources.CrashHandler_UploadRunning);
System.Console.WriteLine(ex.Message);
System.Console.WriteLine(traceBack);
var bckTraceCreds = new MFDLabs.Backtrace.Model.BacktraceCredentials(
global::MFDLabs.Grid.Bot.Properties.Settings.Default.CrashHandlerURL,
global::MFDLabs.Grid.Bot.Properties.Settings.Default.CrashHandlerAccessToken
Expand Down

0 comments on commit 2ff1459

Please sign in to comment.