1
0
Fork 0

Sentry logging of exceptions, fatal errors

This commit is contained in:
Automatic Release Builder 2020-08-23 17:41:34 +01:00 committed by James Turner
parent bade1ec4c6
commit d9b7435dab
4 changed files with 60 additions and 0 deletions

View file

@ -12,6 +12,7 @@
#include <Main/globals.hxx>
#include <Viewer/renderer.hxx>
#include <GUI/new_gui.hxx>
#include <Main/sentryIntegration.hxx>
#include <osgViewer/Viewer>
@ -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 << "\"");

View file

@ -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");

View file

@ -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

View file

@ -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