1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-18 16:32:32 +02:00

config: Add the unknown keys to the what() message

This commit is contained in:
Anonymous Maarten 2017-04-22 03:08:15 +02:00 committed by Daniel Evans
parent a92f24cbb4
commit 0308f809d6

View File

@ -221,8 +221,6 @@ GameConfig::ParseResult GameConfig::parseConfig(GameConfig::ParseType srcType,
read_config("input.invert_y", this->m_inputInvertY, false, boolt); read_config("input.invert_y", this->m_inputInvertY, false, boolt);
if (!parseResult.isValid()) return parseResult;
// Build the unknown key/value map from the correct source // Build the unknown key/value map from the correct source
switch (srcType) { switch (srcType) {
case ParseType::FILE: case ParseType::FILE:
@ -260,6 +258,8 @@ GameConfig::ParseResult GameConfig::parseConfig(GameConfig::ParseType srcType,
break; break;
} }
if (!parseResult.isValid()) return parseResult;
try { try {
if (destType == ParseType::STRING) { if (destType == ParseType::STRING) {
std::ostringstream ostream; std::ostringstream ostream;
@ -363,27 +363,26 @@ const std::vector<std::string> &GameConfig::ParseResult::getKeysInvalidData()
} }
std::string GameConfig::ParseResult::what() const { std::string GameConfig::ParseResult::what() const {
std::ostringstream oss;
switch (this->m_result) { switch (this->m_result) {
case ErrorType::GOOD: case ErrorType::GOOD:
return "Good"; oss << "Parsing completed without errors.";
break;
case ErrorType::INVALIDARGUMENT: case ErrorType::INVALIDARGUMENT:
return "Invalid argument: destination cannot be the default config"; oss << "Invalid argument: destination cannot be the default "
case ErrorType::INVALIDINPUTFILE: { "config.";
std::ostringstream oss; break;
case ErrorType::INVALIDINPUTFILE:
oss << "Error while reading \"" << this->m_inputfilename oss << "Error while reading \"" << this->m_inputfilename
<< "\":" << this->m_line << ":\n" << "\":" << this->m_line << ":\n"
<< this->m_message; << this->m_message << ".";
return oss.str(); break;
} case ErrorType::INVALIDOUTPUTFILE:
case ErrorType::INVALIDOUTPUTFILE: {
std::ostringstream oss;
oss << "Error while writing \"" << this->m_inputfilename oss << "Error while writing \"" << this->m_inputfilename
<< "\":" << this->m_line << ":\n" << "\":" << this->m_line << ":\n"
<< this->m_message; << this->m_message << ".";
return oss.str(); break;
} case ErrorType::INVALIDCONTENT:
case ErrorType::INVALIDCONTENT: {
std::ostringstream oss;
oss << "Error while parsing \"" << this->m_inputfilename << "\"."; oss << "Error while parsing \"" << this->m_inputfilename << "\".";
if (this->m_keys_requiredMissing.size()) { if (this->m_keys_requiredMissing.size()) {
oss << "\nRequired keys that are missing:"; oss << "\nRequired keys that are missing:";
@ -397,11 +396,18 @@ std::string GameConfig::ParseResult::what() const {
oss << "\n - " << key; oss << "\n - " << key;
} }
} }
return oss.str(); break;
}
default: default:
return "Unknown error"; oss << "Unknown error.";
break;
} }
if (this->m_unknownData.size()) {
oss << "\nUnknown configuration keys:";
for (const auto &keyvalue : m_unknownData) {
oss << "\n - " << keyvalue.first;
}
}
return oss.str();
} }
void GameConfig::ParseResult::addUnknownData(const std::string &key, void GameConfig::ParseResult::addUnknownData(const std::string &key,