From d07360b37dd7b921597885c02d3b3b367d11dc3c Mon Sep 17 00:00:00 2001 From: Automatic Release Builder <build@flightgear.org> Date: Sat, 19 Sep 2020 13:15:22 +0100 Subject: [PATCH] Launcher: guard against missing data files More robust checking that FGData is setup correctly, when we try to parse defaults.xml from the launcher. Relates to Sentry exception: https://sentry.io/organizations/flightgear/issues/1901193353 --- src/GUI/DefaultAircraftLocator.cxx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/GUI/DefaultAircraftLocator.cxx b/src/GUI/DefaultAircraftLocator.cxx index 043a82d05..d0dfb6acb 100644 --- a/src/GUI/DefaultAircraftLocator.cxx +++ b/src/GUI/DefaultAircraftLocator.cxx @@ -2,6 +2,7 @@ #include <simgear/props/props_io.hxx> #include <simgear/debug/logstream.hxx> +#include <simgear/structure/exception.hxx> #include <Main/globals.hxx> #include <Main/locale.hxx> @@ -10,11 +11,21 @@ static SGPropertyNode_ptr loadXMLDefaults() { SGPropertyNode_ptr root(new SGPropertyNode); const SGPath defaultsXML = globals->get_fg_root() / "defaults.xml"; - readProperties(defaultsXML, root); + if (!defaultsXML.exists()) { + SG_LOG(SG_GUI, SG_POPUP, "Failed to find required data file (defaults.xml)"); + return {}; + } + + try { + readProperties(defaultsXML, root); + } catch (sg_exception& e) { + SG_LOG(SG_GUI, SG_POPUP, "Failed to read required data file (defaults.xml)"); + return {}; + } if (!root->hasChild("sim")) { SG_LOG(SG_GUI, SG_POPUP, "Failed to find /sim node in defaults.xml, broken"); - return SGPropertyNode_ptr(); + return {}; } return root; @@ -28,7 +39,7 @@ std::string defaultAirportICAO() { SGPropertyNode_ptr root = loadXMLDefaults(); if (!root) { - return std::string(); + return {}; } std::string airportCode = root->getStringValue("/sim/presets/airport-id");