From 14d01ccffe889b6fb82807f250baca750d959032 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 25 Apr 2021 18:55:11 +0100 Subject: [PATCH] Panel/cockpit loading: report errors --- src/Cockpit/cockpitDisplayManager.cxx | 14 ++++++------- src/Cockpit/panel_io.cxx | 29 ++++++++++++++------------ src/Instrumentation/instrument_mgr.cxx | 23 +++++++++++--------- src/Instrumentation/instrument_mgr.hxx | 12 ++--------- 4 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/Cockpit/cockpitDisplayManager.cxx b/src/Cockpit/cockpitDisplayManager.cxx index a706cb69c..6eceb2da6 100644 --- a/src/Cockpit/cockpitDisplayManager.cxx +++ b/src/Cockpit/cockpitDisplayManager.cxx @@ -17,9 +17,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include "cockpitDisplayManager.hxx" @@ -27,6 +25,7 @@ #include #include #include +#include #include
#include
@@ -58,13 +57,13 @@ void CockpitDisplayManager::init() SGPropertyNode_ptr config_props = new SGPropertyNode; SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path"); if (!path_n) { - SG_LOG(SG_COCKPIT, SG_WARN, "No instrumentation model specified for this model!"); return; } SGPath config = globals->resolve_aircraft_path(path_n->getStringValue()); if (!config.exists()) { - SG_LOG(SG_COCKPIT, SG_DEV_ALERT, "CockpitDisplaysManager: Missing instrumentation file at:" << config); + simgear::reportFailure(simgear::LoadFailure::NotFound, simgear::ErrorCode::AircraftSystems, + "CockpitDisplaysManager: Missing instrumentation file", config); return; } @@ -78,8 +77,9 @@ void CockpitDisplayManager::init() "system specification file. See earlier errors for details."); } } catch (const sg_exception& e) { - SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: " - << config << ":" << e.getFormattedMessage() ); + simgear::reportFailure(simgear::LoadFailure::BadData, simgear::ErrorCode::AircraftSystems, + "Failed to load cockpit displays system:" + e.getFormattedMessage(), + e.getLocation()); } SGSubsystemGroup::init(); diff --git a/src/Cockpit/panel_io.cxx b/src/Cockpit/panel_io.cxx index e9c4d2bac..79fa8558f 100644 --- a/src/Cockpit/panel_io.cxx +++ b/src/Cockpit/panel_io.cxx @@ -18,9 +18,7 @@ // // $Id$ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include // for strcmp() @@ -30,6 +28,7 @@ #include #include #include +#include #include #include @@ -37,6 +36,7 @@ #include
#include
+#include
#include @@ -571,7 +571,7 @@ readLayer (const SGPropertyNode * node, float w_scale, float h_scale) * scaled automatically if the instrument is not at its preferred size. */ static FGPanelInstrument * -readInstrument (const SGPropertyNode * node) +readInstrument (const SGPropertyNode * node, const SGPath& path) { const string name = node->getStringValue("name"); int x = node->getIntValue("x", -1); @@ -582,8 +582,8 @@ readInstrument (const SGPropertyNode * node) int h = node->getIntValue("h-base", -1); if (x == -1 || y == -1) { - SG_LOG( SG_COCKPIT, SG_ALERT, - "x and y positions must be specified and > 0" ); + simgear::reportFailure(simgear::LoadFailure::Misconfigured, simgear::ErrorCode::AircraftSystems, + "Panel x and y positions must be specified and > 0", path); return 0; } @@ -650,7 +650,7 @@ readInstrument (const SGPropertyNode * node) * Construct the panel from a property tree. */ FGPanel * -readPanel (const SGPropertyNode * root) +readPanel (const SGPropertyNode * root, const SGPath& path) { SG_LOG( SG_COCKPIT, SG_INFO, "Reading properties for panel " << root->getStringValue("name", "[Unnamed Panel]") ); @@ -742,7 +742,7 @@ readPanel (const SGPropertyNode * root) for (int i = 0; i < nInstruments; i++) { const SGPropertyNode * node = instrument_group->getChild(i); if (!strcmp(node->getName(), "instrument")) { - FGPanelInstrument * instrument = readInstrument(node); + FGPanelInstrument * instrument = readInstrument(node, path); if (instrument != 0) panel->addInstrument(instrument); } else if (!strcmp(node->getName(), "special-instrument")) { @@ -822,12 +822,13 @@ fgReadPanel (istream &input) SGPropertyNode root; try { + flightgear::SentryXMLErrorSupression xs; readProperties(input, &root); } catch (const sg_exception &e) { guiErrorMessage("Error reading panel: ", e); return 0; } - return readPanel(&root); + return readPanel(&root, SGPath{}); } @@ -844,18 +845,20 @@ fgReadPanel (const string &relative_path) SGPropertyNode root; if (!path.exists()) { - auto msg = string{"Missing panel file: "} + relative_path; - guiErrorMessage(msg.c_str()); + simgear::reportFailure(simgear::LoadFailure::NotFound, simgear::ErrorCode::AircraftSystems, + "Missing panel file:" + relative_path, path); return nullptr; } try { + flightgear::SentryXMLErrorSupression xs; readProperties(path, &root); } catch (const sg_exception &e) { - guiErrorMessage("Error reading panel: ", e); + simgear::reportFailure(simgear::LoadFailure::BadData, simgear::ErrorCode::AircraftSystems, + "Error parsing panel file:" + e.getFormattedMessage(), path); return 0; } - return readPanel(&root); + return readPanel(&root, path); } diff --git a/src/Instrumentation/instrument_mgr.cxx b/src/Instrumentation/instrument_mgr.cxx index c66288a26..41f0adbff 100644 --- a/src/Instrumentation/instrument_mgr.cxx +++ b/src/Instrumentation/instrument_mgr.cxx @@ -3,9 +3,7 @@ // // This file is in the Public Domain and comes with no warranty. -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include #include @@ -15,6 +13,7 @@ #include #include #include +#include #include
#include
@@ -68,13 +67,15 @@ void FGInstrumentMgr::init() SGPropertyNode_ptr config_props = new SGPropertyNode; SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path"); if (!path_n) { - SG_LOG(SG_COCKPIT, SG_WARN, "No instrumentation model specified for this model!"); + SG_LOG(SG_COCKPIT, SG_DEV_WARN, "No instrumentation model specified for this model!"); return; } SGPath config = globals->resolve_aircraft_path(path_n->getStringValue()); if (!config.exists()) { SG_LOG(SG_COCKPIT, SG_DEV_ALERT, "Missing instrumentation file at:" << config); + simgear::reportFailure(simgear::LoadFailure::NotFound, simgear::ErrorCode::AircraftSystems, + "FGInstrumentMgr: Missing instrumentation file", config); return; } @@ -82,14 +83,15 @@ void FGInstrumentMgr::init() try { readProperties( config, config_props ); - if (!build(config_props)) { + if (!build(config_props, config)) { throw sg_exception( "Detected an internal inconsistency in the instrumentation\n" "system specification file. See earlier errors for details."); } } catch (const sg_exception& e) { - SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: " - << config << ":" << e.getFormattedMessage() ); + simgear::reportFailure(simgear::LoadFailure::BadData, simgear::ErrorCode::AircraftSystems, + "Failed to load instrumentation system:" + e.getFormattedMessage(), + e.getLocation()); } @@ -105,7 +107,7 @@ void FGInstrumentMgr::init() SGSubsystemGroup::init(); } -bool FGInstrumentMgr::build (SGPropertyNode* config_props) +bool FGInstrumentMgr::build (SGPropertyNode* config_props, const SGPath& path) { for ( int i = 0; i < config_props->nChildren(); ++i ) { SGPropertyNode *node = config_props->getChild(i); @@ -220,8 +222,9 @@ bool FGInstrumentMgr::build (SGPropertyNode* config_props) set_subsystem( id, new TCAS( node ), 0.2); } else { - SG_LOG( SG_INSTR, SG_ALERT, - "Unknown top level section in instrumentation: " << name ); + simgear::reportFailure(simgear::LoadFailure::Misconfigured, simgear::ErrorCode::AircraftSystems, + "Unknown top level section in instrumentation:" + name, + path); continue; } diff --git a/src/Instrumentation/instrument_mgr.hxx b/src/Instrumentation/instrument_mgr.hxx index 43cbf00bc..79e15c6de 100644 --- a/src/Instrumentation/instrument_mgr.hxx +++ b/src/Instrumentation/instrument_mgr.hxx @@ -7,14 +7,6 @@ #ifndef __INSTRUMENT_MGR_HXX #define __INSTRUMENT_MGR_HXX 1 -#ifndef __cplusplus -# error This library requires C++ -#endif - -#ifdef HAVE_CONFIG_H -# include -#endif - #include #include @@ -39,9 +31,9 @@ public: static const char* staticSubsystemClassId() { return "instrumentation"; } private: - bool build (SGPropertyNode* config_props); + bool build (SGPropertyNode* config_props, const SGPath& path); - bool _explicitGps; + bool _explicitGps = false; std::vector _instruments; };