mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-24 19:06:49 +01:00
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user