diff --git a/src/GUI/LocalAircraftCache.cxx b/src/GUI/LocalAircraftCache.cxx index 8a3216821..1918cae07 100644 --- a/src/GUI/LocalAircraftCache.cxx +++ b/src/GUI/LocalAircraftCache.cxx @@ -33,6 +33,7 @@ #include
#include
+#include
#include #include @@ -400,6 +401,11 @@ protected: { 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) { const auto p = SGPath::fromUtf8(d.toUtf8().toStdString()); m_currentScanDir->setCurrentPath(p); diff --git a/src/Main/sentryIntegration.cxx b/src/Main/sentryIntegration.cxx index b792aafe6..75d469666 100644 --- a/src/Main/sentryIntegration.cxx +++ b/src/Main/sentryIntegration.cxx @@ -37,10 +37,37 @@ using namespace std; +bool doesStringMatchPrefixes(const std::string& s, const std::initializer_list& 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 #if defined(HAVE_SENTRY) && !defined(BUILDING_TESTSUITE) static bool static_sentryEnabled = false; +thread_local bool perThread_reportXMLParseErrors = true; #include @@ -53,6 +80,15 @@ 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; + } + sentry_value_t exc = sentry_value_new_object(); sentry_value_set_by_key(exc, "type", sentry_value_new_string("Exception")); @@ -90,17 +126,8 @@ public: return true; } - if (e.debugClass == SG_OSG) { - // 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; - } + if ((e.debugClass == SG_OSG) && doesStringMatchPrefixes(e.message, OSG_messageWhitelist)) { + return true; } flightgear::addSentryBreadcrumb(e.message, (op == SG_WARN) ? "warning" : "error"); @@ -317,6 +344,11 @@ void sentryReportFatalError(const std::string& msg, const std::string& more) sentry_capture_event(event); } +void sentryThreadReportXMLErrors(bool report) +{ + perThread_reportXMLParseErrors = report; +} + } // of namespace #else @@ -363,6 +395,10 @@ void sentryReportFatalError(const std::string&, const std::string&) { } +void sentryThreadReportXMLErrors(bool) +{ +} + } // of namespace #endif diff --git a/src/Main/sentryIntegration.hxx b/src/Main/sentryIntegration.hxx index 70c9f176d..169a010e1 100644 --- a/src/Main/sentryIntegration.hxx +++ b/src/Main/sentryIntegration.hxx @@ -43,5 +43,18 @@ void sentryReportException(const std::string& msg, const std::string& location = 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