From: Arnaud Giersch Date: Thu, 28 Oct 2021 19:36:45 +0000 (+0200) Subject: Be more user-friendly, and give a hint for options wrongly spelled in snake_case. X-Git-Tag: v3.30~290 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/31e410b2c8e60dab6395fe76821aa0325292a077 Be more user-friendly, and give a hint for options wrongly spelled in snake_case. --- diff --git a/src/xbt/config.cpp b/src/xbt/config.cpp index 3d7c730097..1d54b045a1 100644 --- a/src/xbt/config.cpp +++ b/src/xbt/config.cpp @@ -289,7 +289,12 @@ inline ConfigurationElement* Config::get_dict_element(const std::string& name) XBT_INFO("Option %s has been renamed to %s. Consider switching.", name.c_str(), res->get_key().c_str()); return res; } else { - std::string msg = "Bad config key: " + name + "\nExisting config keys:\n"; + std::string msg = "Bad config key: " + name + "\n"; + std::string kebab = name; + std::replace(begin(kebab), end(kebab), '_', '-'); // convert from snake_case to kebab-case + if (options.count(kebab) > 0) + msg += "Did you mean '" + kebab + "'?\n"; + msg += "Existing config keys:\n"; for (auto const& elm : options) msg += " " + elm.first + ": (" + elm.second->get_type_name() + ")" + elm.second->get_string_value() + "\n"; throw std::out_of_range(msg);