Skip to content

Commit

Permalink
feat: Softer and better crash detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
shdwmtr committed Nov 30, 2024
1 parent bf36bd5 commit fc5e756
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <core/py_controller/co_spawn.h>
#include <core/ftp/serv.h>
#include <signal.h>
#include <cxxabi.h>
#include <pipes/terminal_pipe.h>
#include <git/vcs.h>
#include <api/executor.h>
Expand Down Expand Up @@ -47,9 +48,41 @@ class Preload
}
};

void OnTerminate()
{
std::string errorMessage = "Millennium has a fatal error that it can't recover from, check the logs for more details!";

auto const exceptionPtr = std::current_exception();
if (exceptionPtr) {
try {
int status;
auto const exceptionType = abi::__cxa_demangle(abi::__cxa_current_exception_type()->name(), 0, 0, &status);
errorMessage.append("\nTerminating with uncaught exception of type `");
errorMessage.append(exceptionType);
errorMessage.append("`");
std::rethrow_exception(exceptionPtr); // rethrow the exception to catch its exception message
}
catch (const std::exception& e) {
errorMessage.append(" with `what()` = \"");
errorMessage.append(e.what());
errorMessage.append("\"");
}
catch (...) {
}
}

#ifdef _WIN32
MessageBoxA(NULL, errorMessage.c_str(), "Oops!", MB_ICONERROR | MB_OK);
#elif __linux__
std::cerr << errorMessage << std::endl;
#endif
}

/* Wrapped cross platform entrypoint */
const static void EntryMain()
{
std::set_terminate(OnTerminate); // Set custom terminate handler for easier debugging

/** Handle signal interrupts (^C) */
signal(SIGINT, [](int signalCode) { std::exit(128 + SIGINT); });

Expand Down

0 comments on commit fc5e756

Please sign in to comment.