diff --git a/src/GUI/MessageBox.cxx b/src/GUI/MessageBox.cxx index 2ef8f86be..882e2da75 100644 --- a/src/GUI/MessageBox.cxx +++ b/src/GUI/MessageBox.cxx @@ -12,6 +12,7 @@ #include
#include #include +#include
#include @@ -173,6 +174,8 @@ MessageBoxResult fatalMessageBoxWithoutExit(const std::string& caption, const std::string& msg, const std::string& moreText) { + flightgear::sentryReportFatalError(msg, moreText); + // Headless mode. if (static_isHeadless) { SG_LOG(SG_HEADLESS, SG_ALERT, "Fatal Error: \"" << caption << "\""); diff --git a/src/Main/bootstrap.cxx b/src/Main/bootstrap.cxx index 70b9b5097..b1690ac85 100644 --- a/src/Main/bootstrap.cxx +++ b/src/Main/bootstrap.cxx @@ -319,7 +319,10 @@ int main ( int argc, char **argv ) info = std::string("received from ") + t.getOrigin(); flightgear::fatalMessageBoxWithoutExit( "Fatal exception", t.getFormattedMessage(), info); + + flightgear::sentryReportException(t.getFormattedMessage()), t.getOrigin(); } catch (const std::exception &e ) { + flightgear::sentryReportException(e.what()); flightgear::fatalMessageBoxWithoutExit("Fatal exception", e.what()); } catch (const std::string &s) { flightgear::fatalMessageBoxWithoutExit("Fatal exception", s); @@ -328,6 +331,7 @@ int main ( int argc, char **argv ) } catch (const char *s) { std::cerr << "Fatal error (const char*): " << s << std::endl; } catch (...) { + flightgear::sentryReportException("Unknown main loop exception"); std::cerr << "Unknown exception in the main loop. Aborting..." << std::endl; if (errno) perror("Possible cause"); diff --git a/src/Main/sentryIntegration.cxx b/src/Main/sentryIntegration.cxx index 470bdae57..2c66fefbc 100644 --- a/src/Main/sentryIntegration.cxx +++ b/src/Main/sentryIntegration.cxx @@ -176,6 +176,47 @@ void sentryReportNasalError(const std::string& msg, const string_list& stack) #endif } +void sentryReportException(const std::string& msg, const std::string& location) +{ + if (!static_sentryEnabled) + return; + + sentry_value_t exc = sentry_value_new_object(); + sentry_value_set_by_key(exc, "type", sentry_value_new_string("Exception")); + sentry_value_set_by_key(exc, "value", sentry_value_new_string(msg.c_str())); + + if (!location.empty()) { + sentry_value_set_by_key(exc, "location", sentry_value_new_string(location.c_str())); + } + + sentry_value_t event = sentry_value_new_event(); + sentry_value_set_by_key(event, "exception", exc); + + // capture the C++ stack-trace. Probably not that useful but can't hurt + sentry_event_value_add_stacktrace(event, nullptr, 0); + sentry_capture_event(event); +} + +void sentryReportFatalError(const std::string& msg, const std::string& more) +{ + if (!static_sentryEnabled) + return; + + sentry_value_t exc = sentry_value_new_object(); + sentry_value_set_by_key(exc, "type", sentry_value_new_string("Fatal Error")); + sentry_value_set_by_key(exc, "message", sentry_value_new_string(msg.c_str())); + + if (!more.empty()) { + sentry_value_set_by_key(exc, "more", sentry_value_new_string(more.c_str())); + } + + sentry_value_t event = sentry_value_new_event(); + sentry_value_set_by_key(event, "error", exc); + + sentry_event_value_add_stacktrace(event, nullptr, 0); + sentry_capture_event(event); +} + } // of namespace #else @@ -214,6 +255,14 @@ void sentryReportNasalError(const std::string&, const string_list&) { } +void sentryReportException(const std::string&, const std::string&) +{ +} + +void sentryReportFatalError(const std::string&, const std::string&) +{ +} + } // of namespace #endif diff --git a/src/Main/sentryIntegration.hxx b/src/Main/sentryIntegration.hxx index cfbb436dc..70c9f176d 100644 --- a/src/Main/sentryIntegration.hxx +++ b/src/Main/sentryIntegration.hxx @@ -39,5 +39,9 @@ void addSentryTag(const std::string& tag, const std::string& value); void sentryReportNasalError(const std::string& msg, const string_list& stack); +void sentryReportException(const std::string& msg, const std::string& location = {}); + +void sentryReportFatalError(const std::string& msg, const std::string& more = {}); + } // of namespace flightgear