From 0c5e9241f158f0700c5576ae6f37d8ede971ab4a Mon Sep 17 00:00:00 2001 From: titiger Date: Tue, 22 Nov 2016 22:58:57 +0100 Subject: [PATCH] trying to get better error output on xml errors. --- source/glest_game/game/game.cpp | 4 --- source/shared_lib/sources/xml/xml_parser.cpp | 30 ++++++++++---------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index b2a841ca..0b2608c0 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1122,8 +1122,6 @@ void Game::load(int loadTypes) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); set factions; - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - for ( int i=0; i < gameSettings.getFactionCount(); ++i ) { factions.insert(gameSettings.getFactionTypeName(i)); } @@ -2683,9 +2681,7 @@ void Game::update() { renderer.endScenario(); world.clearTileset(); this->setGameSettings(&gameSettings); - this->load(lgt_FactionPreview | lgt_TileSet | lgt_Map | lgt_Scenario); - try { world.init(this, gameSettings.getDefaultUnits(),false); } diff --git a/source/shared_lib/sources/xml/xml_parser.cpp b/source/shared_lib/sources/xml/xml_parser.cpp index 47cfad3f..fa20ec5f 100644 --- a/source/shared_lib/sources/xml/xml_parser.cpp +++ b/source/shared_lib/sources/xml/xml_parser.cpp @@ -351,7 +351,7 @@ XmlNode *XmlIoRapid::load(const string &path, const std::map &map try { if(folderExists(path) == true) { - throw megaglest_runtime_error("Can not open file: [" + path + "] as it is a folder!"); + throw megaglest_runtime_error("Can not open file: [" + path + "] as it is a folder!",true); } #if defined(WIN32) && !defined(__MINGW32__) @@ -361,7 +361,7 @@ XmlNode *XmlIoRapid::load(const string &path, const std::map &map ifstream xmlFile(path.c_str(),ios::binary); #endif if(xmlFile.is_open() == false) { - throw megaglest_runtime_error("Can not open file: [" + path + "]"); + throw megaglest_runtime_error("Can not open file: [" + path + "]",true); } if(showPerfStats) printf("In [%s::%s Line: %d] took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); @@ -620,7 +620,7 @@ XmlTree::~XmlTree() { XmlNode::XmlNode(DOMNode *node, const std::map &mapTagReplacementValues): superNode(NULL) { if(node == NULL || node->getNodeName() == NULL) { - throw megaglest_runtime_error("XML structure seems to be corrupt!"); + throw megaglest_runtime_error("XML structure seems to be corrupt!",true); } //get name @@ -670,7 +670,7 @@ XmlNode::XmlNode(DOMNode *node, const std::map &mapTagReplacement XmlNode::XmlNode(xml_node<> *node, const std::map &mapTagReplacementValues, bool skipUpdatePathClimbingParts) : superNode(NULL) { if(node == NULL || node->name() == NULL) { - throw megaglest_runtime_error("XML structure seems to be corrupt!"); + throw megaglest_runtime_error("XML structure seems to be corrupt!",true); } //get name @@ -735,7 +735,7 @@ XmlNode::~XmlNode() { XmlAttribute *XmlNode::getAttribute(unsigned int i) const { if(i >= attributes.size()) { - throw megaglest_runtime_error(getName()+" node doesn't have " + uIntToStr(i) + " attributes"); + throw megaglest_runtime_error(getName()+" node doesn't have " + uIntToStr(i) + " attributes",true); } return attributes[i]; } @@ -747,7 +747,7 @@ XmlAttribute *XmlNode::getAttribute(const string &name,bool mustExist) const { } } if(mustExist == true) { - throw megaglest_runtime_error("\"" + getName() + "\" node doesn't have a attribute named \"" + name + "\""); + throw megaglest_runtime_error("\"" + getName() + "\" node doesn't have a attribute named \"" + name + "\"",true); } return NULL; @@ -779,7 +779,7 @@ int XmlNode::clearChild(const string &childName) { XmlNode *XmlNode::getChild(unsigned int i) const { assert(!superNode); if(i >= children.size()) { - throw megaglest_runtime_error("\"" + getName()+"\" node doesn't have "+ uIntToStr(i+1) + " children"); + throw megaglest_runtime_error("\"" + getName()+"\" node doesn't have "+ uIntToStr(i+1) + " children", true); } return children[i]; } @@ -800,7 +800,7 @@ XmlNode *XmlNode::getChild(const string &childName, unsigned int i) const { return superNode->getChild(childName,i); } if(i >= children.size()) { - throw megaglest_runtime_error("\"" + name + "\" node doesn't have " + uIntToStr(i+1) +" children named \"" + childName + "\"\n\nTree: "+getTreeString()); + throw megaglest_runtime_error("\"" + name + "\" node doesn't have " + uIntToStr(i+1) +" children named \"" + childName + "\"\n\nTree: "+getTreeString(),true); } unsigned int count= 0; @@ -813,7 +813,7 @@ XmlNode *XmlNode::getChild(const string &childName, unsigned int i) const { } } - throw megaglest_runtime_error("Node \""+getName()+"\" doesn't have " + uIntToStr(i+1) + " children named \""+childName+"\"\n\nTree: "+getTreeString()); + throw megaglest_runtime_error("Node \""+getName()+"\" doesn't have " + uIntToStr(i+1) + " children named \""+childName+"\"\n\nTree: "+getTreeString(),true); } bool XmlNode::hasChildNoSuper(const string &childName) const { @@ -832,7 +832,7 @@ XmlNode * XmlNode::getChildWithAliases(vector childNameList, unsigned in return superNode->getChild(childName,childIndex); } if(childIndex >= children.size()) { - throw megaglest_runtime_error("\"" + name + "\" node doesn't have "+intToStr(childIndex+1)+" children named \"" + childName + "\"\n\nTree: "+getTreeString()); + throw megaglest_runtime_error("\"" + name + "\" node doesn't have "+intToStr(childIndex+1)+" children named \"" + childName + "\"\n\nTree: "+getTreeString(),true); } unsigned int count= 0; @@ -846,7 +846,7 @@ XmlNode * XmlNode::getChildWithAliases(vector childNameList, unsigned in } } - throw megaglest_runtime_error("Node \""+getName()+"\" doesn't have "+intToStr(childIndex+1)+" children named \""+ (childNameList.empty() ? "???" : childNameList[0]) +"\"\n\nTree: "+getTreeString()); + throw megaglest_runtime_error("Node \""+getName()+"\" doesn't have "+intToStr(childIndex+1)+" children named \""+ (childNameList.empty() ? "???" : childNameList[0]) +"\"\n\nTree: "+getTreeString(),true); } bool XmlNode::hasChildAtIndex(const string &childName, int i) const { @@ -1026,7 +1026,7 @@ bool XmlAttribute::getBoolValue() const { return false; } else { - throw megaglest_runtime_error("Not a valid bool value (true or false): " +getName()+": "+ value); + throw megaglest_runtime_error("Not a valid bool value (true or false): " +getName()+": "+ value,true); } } @@ -1041,7 +1041,7 @@ uint32 XmlAttribute::getUIntValue() const { int XmlAttribute::getIntValue(int min, int max) const { int i= strToInt(value); if(imax){ - throw megaglest_runtime_error("Xml Attribute int out of range: " + getName() + ": " + value); + throw megaglest_runtime_error("Xml Attribute int out of range: " + getName() + ": " + value,true); } return i; } @@ -1054,7 +1054,7 @@ float XmlAttribute::getFloatValue(float min, float max) const{ float f= strToFloat(value); //printf("getFloatValue f = %.10f [%s]\n",f,value.c_str()); if(fmax){ - throw megaglest_runtime_error("Xml attribute float out of range: " + getName() + ": " + value); + throw megaglest_runtime_error("Xml attribute float out of range: " + getName() + ": " + value,true); } return f; } @@ -1078,7 +1078,7 @@ const string XmlAttribute::getRestrictedValue(string prefixValue, bool trimValue if(allowedCharacters.find(value[i])==string::npos){ throw megaglest_runtime_error( string("The string \"" + value + "\" contains a character that is not allowed: \"") + value[i] + - "\"\nFor portability reasons the only allowed characters in this field are: " + allowedCharacters); + "\"\nFor portability reasons the only allowed characters in this field are: " + allowedCharacters,true); } } }