From 15dfc492dceb465bed8941e81b0c4c2c6ba7748d Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 24 Feb 2021 14:47:01 +0000 Subject: [PATCH] AIModelData: add error report context Not complete yet, but add the ability to pass context in from the AIBase to the loader thread. Also add error context to more places in AI / scenario loading. --- src/AIModel/AIBase.cxx | 19 +++++++++++++++++-- src/AIModel/AIManager.cxx | 6 ++++-- src/Scripting/NasalModelData.hxx | 5 +++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 6a91b0d68..a22b526cc 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -32,11 +32,12 @@ #include #include +#include +#include #include +#include #include #include -#include -#include #include
#include
@@ -68,6 +69,16 @@ public: FGAIModelData* clone() const override { return new FGAIModelData(); } + ErrorContext getErrorContext() const override + { + return _errorContext; + } + + void addErrorContext(const std::string& key, std::string& value) + { + _errorContext[key] = value; + } + /** osg callback, thread-safe */ void modelLoaded(const std::string& path, SGPropertyNode *prop, osg::Node *n) { @@ -120,6 +131,8 @@ private: bool _interiorLoaded = false; float _radius = -1.0; SGPropertyNode* _root; + + ErrorContext _errorContext; }; FGAIBase::FGAIBase(object_type ot, bool enableHot) : @@ -307,6 +320,7 @@ void FGAIBase::update(double dt) { const string& fxpath = _modeldata->get_sound_path(); if (fxpath != "") { + simgear::ErrorReportContext ec("ai-model", _name); props->setStringValue("sim/sound/path", fxpath.c_str()); // Remove any existing sound FX (e.g. from another model) @@ -603,6 +617,7 @@ bool FGAIBase::init(ModelSearchOrder searchOrder) props->addChild("type")->setStringValue("AI"); _modeldata = new FGAIModelData(props); + _modeldata->addErrorContext("ai", _name); vector model_list = resolveModelPath(searchOrder); _model= SGModelLib::loadPagedModel(model_list, props, _modeldata); diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index 961642266..51b1c26fa 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -58,6 +58,7 @@ public: Scenario(FGAIManager* man, const std::string& nm, SGPropertyNode* scenarios) : _internalName(nm) { + simgear::ErrorReportContext ec("scenario-name", _internalName); for (auto scEntry : scenarios->getChildren("entry")) { FGAIBasePtr ai = man->addObject(scEntry); if (ai) { @@ -220,7 +221,7 @@ SGPropertyNode_ptr FGAIManager::registerScenarioFile(SGPropertyNode_ptr root, co auto scenariosNode = root->getNode("/sim/ai/scenarios", true); SGPropertyNode_ptr sNode; - simgear::ErrorReportContext ectx("scenario", xmlPath.utf8Str()); + simgear::ErrorReportContext ectx("scenario-path", xmlPath.utf8Str()); // don't report XML errors while loading scenarios, to Sentry flightgear::SentryXMLErrorSupression xml; @@ -601,7 +602,7 @@ FGAIBasePtr FGAIManager::getObjectFromProperty(const SGPropertyNode* aProp) cons bool FGAIManager::loadScenario( const string &id ) { - simgear::ErrorReportContext("scenario", id); + simgear::ErrorReportContext ec("scenario", id); SGPropertyNode_ptr file = loadScenarioFile(id); if (!file) { return false; @@ -665,6 +666,7 @@ FGAIManager::loadScenarioFile(const std::string& scenarioName) for (auto n : s->getChildren("scenario")) { if (n->getStringValue("id") == scenarioName) { SGPath path{n->getStringValue("path")}; + simgear::ErrorReportContext ec("scenario-path", path.utf8Str()); try { SGPropertyNode_ptr root = new SGPropertyNode; readProperties(path, root); diff --git a/src/Scripting/NasalModelData.hxx b/src/Scripting/NasalModelData.hxx index dbe59b761..4353c23b0 100644 --- a/src/Scripting/NasalModelData.hxx +++ b/src/Scripting/NasalModelData.hxx @@ -91,6 +91,11 @@ public: virtual FGNasalModelDataProxy* clone() const { return new FGNasalModelDataProxy(_root); } + ErrorContext getErrorContext() const override + { + return {}; // return nothing for now, not yet clear if this proxy needs it + } + protected: SGPropertyNode_ptr _root; FGNasalModelDataRef _data;