From 8e90e4657fd0e4aba528073e87489462a154bff1 Mon Sep 17 00:00:00 2001
From: James Turner <james@flightgear.org>
Date: Sat, 26 Jun 2021 16:25:14 +0100
Subject: [PATCH] =?UTF-8?q?Sentry:=20add=20=E2=80=98updateTag=E2=80=99=20h?=
 =?UTF-8?q?elper=20to=20modify=20tags?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Use this to fix reported tags in a few erroneous places.
---
 src/Airports/xmlloader.cxx     |  9 +++++----
 src/Main/fg_init.cxx           |  2 +-
 src/Main/sentryIntegration.cxx | 17 +++++++++++++++++
 src/Main/sentryIntegration.hxx |  3 +++
 4 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/src/Airports/xmlloader.cxx b/src/Airports/xmlloader.cxx
index b12a42389..51c02e279 100644
--- a/src/Airports/xmlloader.cxx
+++ b/src/Airports/xmlloader.cxx
@@ -58,8 +58,8 @@ void XMLLoader::load(FGGroundNetwork* net)
       FGGroundNetXMLLoader visitor(net);
       readXML(path, visitor);
 
-      if (visitor.hasErrors()) {
-          flightgear::addSentryTag("ground-net", net->airport()->ident());
+      if (visitor.hasErrors() && fgGetBool("/sim/terrasync/enabled")) {
+          flightgear::updateSentryTag("ground-net", net->airport()->ident());
           flightgear::sentryReportException("Ground-net load error", path.utf8Str());
       }
   } catch (sg_exception& e) {
@@ -90,8 +90,9 @@ void XMLLoader::loadFromPath(FGGroundNetwork* net, const SGPath& path)
       flightgear::SentryXMLErrorSupression xs;
       FGGroundNetXMLLoader visitor(net);
       readXML(path, visitor);
-      if (visitor.hasErrors()) {
-          flightgear::addSentryTag("ground-net", net->airport()->ident());
+
+      if (visitor.hasErrors() && fgGetBool("/sim/terrasync/enabled")) {
+          flightgear::updateSentryTag("ground-net", net->airport()->ident());
           flightgear::sentryReportException("Ground-net load error", path.utf8Str());
       }
   } catch (sg_exception& e) {
diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx
index e3afd1690..6e28d73f0 100755
--- a/src/Main/fg_init.cxx
+++ b/src/Main/fg_init.cxx
@@ -1202,7 +1202,7 @@ void fgStartReposition()
 
 void fgStartNewReset()
 {
-    flightgear::addSentryTag("have-reset", "yes");
+    flightgear::updateSentryTag("have-reset", "yes");
 
     // save user settings now, so that USERARCIVE-d values changes since the
     // last init are recorded and hence re-loaded when we fgInitConfig down
diff --git a/src/Main/sentryIntegration.cxx b/src/Main/sentryIntegration.cxx
index c9e29dc06..3c85aa6af 100644
--- a/src/Main/sentryIntegration.cxx
+++ b/src/Main/sentryIntegration.cxx
@@ -403,6 +403,18 @@ void addSentryTag(const char* tag, const char* value)
     sentry_set_tag(tag, value);
 }
 
+void updateSentryTag(const std::string& tag, const std::string& value)
+{
+    if (tag.empty() || value.empty())
+        return;
+
+    if (!static_sentryEnabled)
+        return;
+
+    sentry_remove_tag(tag.c_str());
+    sentry_set_tag(tag.c_str(), value.c_str());
+}
+
 void sentryReportNasalError(const std::string& msg, const string_list& stack)
 {
     if (!static_sentryEnabled)
@@ -538,6 +550,11 @@ void addSentryTag(const char*, const char*)
 {
 }
 
+void updateSentryTag(const std::string&, const std::string&)
+{
+}
+
+
 void sentryReportNasalError(const std::string&, const string_list&)
 {
 }
diff --git a/src/Main/sentryIntegration.hxx b/src/Main/sentryIntegration.hxx
index 97e5f9fa3..16b6142d4 100644
--- a/src/Main/sentryIntegration.hxx
+++ b/src/Main/sentryIntegration.hxx
@@ -37,6 +37,9 @@ void addSentryTag(const char* tag, const char* value);
 
 void addSentryTag(const std::string& tag, const std::string& value);
 
+void updateSentryTag(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 = {});