1
0
Fork 0

Sentry: block XML parse errors from the launcher

Avoid filling up the logs when the launcher parses broken aircraft XML;
wait until the user actually pick one to fly with, before reporting
XML errors.
This commit is contained in:
Automatic Release Builder 2020-10-13 22:04:33 +01:00 committed by James Turner
parent fc037de312
commit 3e72fb230f
3 changed files with 66 additions and 11 deletions

View file

@ -33,6 +33,7 @@
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Main/locale.hxx> #include <Main/locale.hxx>
#include <Main/sentryIntegration.hxx>
#include <simgear/misc/ResourceManager.hxx> #include <simgear/misc/ResourceManager.hxx>
#include <simgear/props/props_io.hxx> #include <simgear/props/props_io.hxx>
@ -400,6 +401,11 @@ protected:
{ {
readCache(); readCache();
// avoid filling up Sentry with many reports
// from unmaintained aircraft. We'll still fail if soemeone tries
// to use the aircraft, but that's 100x less common.
flightgear::sentryThreadReportXMLErrors(false);
Q_FOREACH(QString d, m_dirs) { Q_FOREACH(QString d, m_dirs) {
const auto p = SGPath::fromUtf8(d.toUtf8().toStdString()); const auto p = SGPath::fromUtf8(d.toUtf8().toStdString());
m_currentScanDir->setCurrentPath(p); m_currentScanDir->setCurrentPath(p);

View file

@ -37,10 +37,37 @@
using namespace std; using namespace std;
bool doesStringMatchPrefixes(const std::string& s, const std::initializer_list<const char*>& prefixes)
{
if (s.empty())
return false;
for (auto c : prefixes) {
if (s.find(c) == 0)
return true;
}
return false;
}
auto OSG_messageWhitelist = {
"PNG lib warning : iCCP: known incorrect sRGB profile",
"PNG lib warning : iCCP: profile 'ICC Profile': 1000000h: invalid rendering intent",
"osgDB ac3d reader: detected surface with less than 3",
"osgDB ac3d reader: detected line with less than 2"
};
auto XML_messageWhitelist = {
"Cannot open file",
"not well-formed (invalid token)",
};
// we don't want sentry enabled for the test suite // we don't want sentry enabled for the test suite
#if defined(HAVE_SENTRY) && !defined(BUILDING_TESTSUITE) #if defined(HAVE_SENTRY) && !defined(BUILDING_TESTSUITE)
static bool static_sentryEnabled = false; static bool static_sentryEnabled = false;
thread_local bool perThread_reportXMLParseErrors = true;
#include <sentry.h> #include <sentry.h>
@ -53,6 +80,15 @@ void sentryTraceSimgearThrow(const std::string& msg, const std::string& origin,
if (!static_sentryEnabled) if (!static_sentryEnabled)
return; 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;
}
sentry_value_t exc = sentry_value_new_object(); 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, "type", sentry_value_new_string("Exception"));
@ -90,18 +126,9 @@ public:
return true; return true;
} }
if (e.debugClass == SG_OSG) { if ((e.debugClass == SG_OSG) && doesStringMatchPrefixes(e.message, OSG_messageWhitelist)) {
// white-list certain common OSG warnings to avoid filling up the
// breadcrumbs with noise
if ((e.message == "PNG lib warning : iCCP: known incorrect sRGB profile")
|| (e.message == "PNG lib warning : iCCP: profile 'ICC Profile': 1000000h: invalid rendering intent")
|| (e.message.find("osgDB ac3d reader: detected surface with less than 3") == 0)
|| (e.message.find("osgDB ac3d reader: detected line with less than 2") == 0)
)
{
return true; return true;
} }
}
flightgear::addSentryBreadcrumb(e.message, (op == SG_WARN) ? "warning" : "error"); flightgear::addSentryBreadcrumb(e.message, (op == SG_WARN) ? "warning" : "error");
return true; return true;
@ -317,6 +344,11 @@ void sentryReportFatalError(const std::string& msg, const std::string& more)
sentry_capture_event(event); sentry_capture_event(event);
} }
void sentryThreadReportXMLErrors(bool report)
{
perThread_reportXMLParseErrors = report;
}
} // of namespace } // of namespace
#else #else
@ -363,6 +395,10 @@ void sentryReportFatalError(const std::string&, const std::string&)
{ {
} }
void sentryThreadReportXMLErrors(bool)
{
}
} // of namespace } // of namespace
#endif #endif

View file

@ -43,5 +43,18 @@ void sentryReportException(const std::string& msg, const std::string& location =
void sentryReportFatalError(const std::string& msg, const std::string& more = {}); void sentryReportFatalError(const std::string& msg, const std::string& more = {});
/**
* @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);
} // of namespace flightgear } // of namespace flightgear