diff options
author | DDuarte <dnpd.dd@gmail.com> | 2014-07-29 01:47:00 +0100 |
---|---|---|
committer | DDuarte <dnpd.dd@gmail.com> | 2014-07-29 01:47:00 +0100 |
commit | 0e52b111f3731611ff6c5be2bf0bd849d4e012fb (patch) | |
tree | b2f1f6a1b16ab79078fdce924e088ca162b630db /src | |
parent | 833195062c310685b479ed16ff4ac5ef5664c021 (diff) |
Core/Config: User-friendlyfy configuration parsing errors
It will now print useful error messages that pinpoint the issue
with the config file (missing file, bad syntax, etc)
In memory of MitchesD that lost 18 hours finding a problem with
his config because of a duplicated line.
Diffstat (limited to 'src')
-rw-r--r-- | src/server/authserver/Main.cpp | 6 | ||||
-rw-r--r-- | src/server/game/World/World.cpp | 5 | ||||
-rw-r--r-- | src/server/shared/Configuration/Config.cpp | 17 | ||||
-rw-r--r-- | src/server/shared/Configuration/Config.h | 4 | ||||
-rw-r--r-- | src/server/worldserver/Main.cpp | 6 |
5 files changed, 23 insertions, 15 deletions
diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp index 7c2ed4951c5..69e0d5a1e64 100644 --- a/src/server/authserver/Main.cpp +++ b/src/server/authserver/Main.cpp @@ -68,10 +68,10 @@ int main(int argc, char** argv) if (vm.count("help")) return 0; - if (!sConfigMgr->LoadInitial(configFile)) + std::string configError; + if (!sConfigMgr->LoadInitial(configFile, configError)) { - printf("Invalid or missing configuration file : %s\n", configFile.c_str()); - printf("Verify that the file exists and has \'[authserver]\' written in the top of the file!\n"); + printf("Error in config file: %s\n", configError.c_str()); return 1; } diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index 533fbe6b2a4..bc1058d931d 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -408,9 +408,10 @@ void World::LoadConfigSettings(bool reload) { if (reload) { - if (!sConfigMgr->Reload()) + std::string configError; + if (!sConfigMgr->Reload(configError)) { - TC_LOG_ERROR("misc", "World settings reload fail: can't read settings from %s.", sConfigMgr->GetFilename().c_str()); + TC_LOG_ERROR("misc", "World settings reload fail: %s.", configError.c_str()); return; } sLog->LoadFromConfig(); diff --git a/src/server/shared/Configuration/Config.cpp b/src/server/shared/Configuration/Config.cpp index ecebf30182e..6b83f562520 100644 --- a/src/server/shared/Configuration/Config.cpp +++ b/src/server/shared/Configuration/Config.cpp @@ -25,7 +25,7 @@ using namespace boost::property_tree; -bool ConfigMgr::LoadInitial(std::string const& file) +bool ConfigMgr::LoadInitial(std::string const& file, std::string& error) { std::lock_guard<std::mutex> lock(_configLock); @@ -34,25 +34,32 @@ bool ConfigMgr::LoadInitial(std::string const& file) try { ptree fullTree; - boost::property_tree::ini_parser::read_ini(file, fullTree); + ini_parser::read_ini(file, fullTree); if (fullTree.empty()) + { + error = "empty file (" + file + ")"; return false; + } // Since we're using only one section per config file, we skip the section and have direct property access _config = fullTree.begin()->second; } - catch (std::exception const& /*ex*/) + catch (ini_parser::ini_parser_error const& e) { + if (e.line() == 0) + error = e.message() + " (" + e.filename() + ")"; + else + error = e.message() + " (" + e.filename() + ":" + std::to_string(e.line()) + ")"; return false; } return true; } -bool ConfigMgr::Reload() +bool ConfigMgr::Reload(std::string& error) { - return LoadInitial(_filename.c_str()); + return LoadInitial(_filename.c_str(), error); } std::string ConfigMgr::GetStringDefault(std::string const& name, const std::string& def) diff --git a/src/server/shared/Configuration/Config.h b/src/server/shared/Configuration/Config.h index 42c3a700f3f..ff0233b5669 100644 --- a/src/server/shared/Configuration/Config.h +++ b/src/server/shared/Configuration/Config.h @@ -31,7 +31,7 @@ class ConfigMgr public: /// Method used only for loading main configuration files (authserver.conf and worldserver.conf) - bool LoadInitial(std::string const& file); + bool LoadInitial(std::string const& file, std::string& error); static ConfigMgr* instance() { @@ -39,7 +39,7 @@ public: return &instance; } - bool Reload(); + bool Reload(std::string& error); std::string GetStringDefault(std::string const& name, const std::string& def); bool GetBoolDefault(std::string const& name, bool def); diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index 02e6268cd26..3afa9e84e8b 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -109,10 +109,10 @@ extern int main(int argc, char** argv) WinServiceRun(); #endif - if (!sConfigMgr->LoadInitial(configFile)) + std::string configError; + if (!sConfigMgr->LoadInitial(configFile, configError)) { - printf("Invalid or missing configuration file : %s\n", configFile.c_str()); - printf("Verify that the file exists and has \'[worldserver]' written in the top of the file!\n"); + printf("Error in config file: %s\n", configError.c_str()); return 1; } |