Sentry: bad_alloc suppression feature
Allow supression of bad_alloc reports based on a RAII helper. This will allow reducing backend reports for code-paths where we know bad_alloc is handled.
This commit is contained in:
parent
8535126a7d
commit
e72f8e0286
2 changed files with 18 additions and 57 deletions
|
@ -61,17 +61,6 @@ auto OSG_messageWhitelist = {
|
|||
"Detected particle system using segment(s) with less than 2 vertices"
|
||||
};
|
||||
|
||||
auto XML_messageWhitelist = {
|
||||
"Cannot open file",
|
||||
"not well-formed (invalid token)",
|
||||
"mismatched tag",
|
||||
"syntax error",
|
||||
"no element found",
|
||||
"Root element name is",
|
||||
"XML or text declaration not at start of entity",
|
||||
"Failed to open file",
|
||||
"unclosed token"};
|
||||
|
||||
auto exception_messageWhitelist = {
|
||||
"position is invalid, NaNs", ///< avoid spam when NaNs occur
|
||||
"bad AI flight plan", ///< adjusting logic to avoid this is tricky
|
||||
|
@ -87,7 +76,7 @@ auto exception_messageWhitelist = {
|
|||
#if defined(HAVE_SENTRY) && !defined(BUILDING_TESTSUITE)
|
||||
|
||||
static bool static_sentryEnabled = false;
|
||||
thread_local bool perThread_reportXMLParseErrors = true;
|
||||
thread_local bool perThread_reportAllocErrors = true;
|
||||
|
||||
#include <sentry.h>
|
||||
|
||||
|
@ -100,15 +89,6 @@ void sentryTraceSimgearThrow(const std::string& msg, const std::string& origin,
|
|||
if (!static_sentryEnabled)
|
||||
return;
|
||||
|
||||
// don't report the exceptions raised by easyxml.cxx, if this per-thread
|
||||
// flag is set. This avoids a lot of errors when the launcher scans
|
||||
// directories containing many aircraft of unknown origin/quality
|
||||
// if the user tries to fly with one, we'll still get an error then,
|
||||
// but that's a real failure point (from the user PoV)
|
||||
if (!perThread_reportXMLParseErrors && doesStringMatchPrefixes(msg, XML_messageWhitelist)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (doesStringMatchPrefixes(msg, exception_messageWhitelist)) {
|
||||
return;
|
||||
}
|
||||
|
@ -221,17 +201,19 @@ void sentrySimgearReportCallback(const string& msg, const string& more, bool isF
|
|||
|
||||
void sentryReportBadAlloc()
|
||||
{
|
||||
sentry_value_t sentryMessage = sentry_value_new_object();
|
||||
sentry_value_set_by_key(sentryMessage, "type", sentry_value_new_string("Fatal Error"));
|
||||
sentry_value_set_by_key(sentryMessage, "formatted", sentry_value_new_string("bad allocation"));
|
||||
if (perThread_reportAllocErrors) {
|
||||
sentry_value_t sentryMessage = sentry_value_new_object();
|
||||
sentry_value_set_by_key(sentryMessage, "type", sentry_value_new_string("Fatal Error"));
|
||||
sentry_value_set_by_key(sentryMessage, "formatted", sentry_value_new_string("bad allocation"));
|
||||
|
||||
sentry_value_t event = sentry_value_new_event();
|
||||
sentry_value_set_by_key(event, "message", sentryMessage);
|
||||
sentry_value_t event = sentry_value_new_event();
|
||||
sentry_value_set_by_key(event, "message", sentryMessage);
|
||||
|
||||
sentry_event_value_add_stacktrace(event, nullptr, 0);
|
||||
sentry_capture_event(event);
|
||||
sentry_event_value_add_stacktrace(event, nullptr, 0);
|
||||
sentry_capture_event(event);
|
||||
}
|
||||
|
||||
std::set_new_handler(nullptr);
|
||||
throw std::bad_alloc(); // allow normal processing
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -492,11 +474,6 @@ void sentryReportFatalError(const std::string& msg, const std::string& more)
|
|||
sentry_capture_event(event);
|
||||
}
|
||||
|
||||
void sentryThreadReportXMLErrors(bool report)
|
||||
{
|
||||
perThread_reportXMLParseErrors = report;
|
||||
}
|
||||
|
||||
void sentryReportUserError(const std::string& aggregate, const std::string& details)
|
||||
{
|
||||
if (!static_sentryEnabled)
|
||||
|
@ -567,10 +544,6 @@ void sentryReportFatalError(const std::string&, const std::string&)
|
|||
{
|
||||
}
|
||||
|
||||
void sentryThreadReportXMLErrors(bool)
|
||||
{
|
||||
}
|
||||
|
||||
void sentryReportUserError(const std::string&, const std::string&)
|
||||
{
|
||||
}
|
||||
|
@ -592,14 +565,14 @@ void addSentryTag(const std::string& tag, const std::string& value)
|
|||
addSentryTag(tag.c_str(), value.c_str());
|
||||
}
|
||||
|
||||
SentryXMLErrorSupression::SentryXMLErrorSupression()
|
||||
SentryAllocErrorSupression::SentryAllocErrorSupression()
|
||||
{
|
||||
sentryThreadReportXMLErrors(false);
|
||||
perThread_reportAllocErrors = false;
|
||||
}
|
||||
|
||||
SentryXMLErrorSupression::~SentryXMLErrorSupression()
|
||||
SentryAllocErrorSupression::~SentryAllocErrorSupression()
|
||||
{
|
||||
sentryThreadReportXMLErrors(true);
|
||||
perThread_reportAllocErrors = true;
|
||||
}
|
||||
|
||||
} // of namespace flightgear
|
||||
|
|
|
@ -47,24 +47,12 @@ void sentryReportException(const std::string& msg, const std::string& location =
|
|||
void sentryReportFatalError(const std::string& msg, const std::string& more = {});
|
||||
|
||||
void sentryReportUserError(const std::string& aggregate, const std::string& details);
|
||||
/**
|
||||
* @brief helper to allow per-thread supression of
|
||||
* error reports based on XML parse/include errors.
|
||||
* This is to reduce noise from the launhcer scanning large
|
||||
* directories of non-fixlbe aircraft, in a helper thread.
|
||||
*
|
||||
* We do it at this level since we don't want to modify
|
||||
* the SimGear XML parser, so we set a thread-local flag
|
||||
* and use it to avoid reporting the exception when it
|
||||
* occurs.
|
||||
*/
|
||||
void sentryThreadReportXMLErrors(bool report);
|
||||
|
||||
class SentryXMLErrorSupression
|
||||
class SentryAllocErrorSupression
|
||||
{
|
||||
public:
|
||||
SentryXMLErrorSupression();
|
||||
~SentryXMLErrorSupression();
|
||||
SentryAllocErrorSupression();
|
||||
~SentryAllocErrorSupression();
|
||||
};
|
||||
|
||||
} // of namespace flightgear
|
||||
|
|
Loading…
Reference in a new issue