Improve error handling when parsing config, fix specifying IP address
This commit is contained in:
parent
eb2b55c834
commit
046f963f4b
|
@ -50,9 +50,9 @@ inline void convertValue(const std::multimap<std::string, std::string> &multimap
|
||||||
if (const char *const value = getLastValue(multimap, key)) {
|
if (const char *const value = getLastValue(multimap, key)) {
|
||||||
boost::system::error_code error;
|
boost::system::error_code error;
|
||||||
const auto ip = boost::asio::ip::make_address(value, error);
|
const auto ip = boost::asio::ip::make_address(value, error);
|
||||||
if (ip.is_unspecified()) {
|
if (error) {
|
||||||
cerr << Phrases::Error << "Specified IP address \"" << value << "\" for key \"" << key << "\" is invalid" << Phrases::End << " "
|
cerr << Phrases::ErrorMessage << "Specified IP address \"" << value << "\" for key \"" << key << "\" is invalid" << Phrases::End
|
||||||
<< error.message() << endl;
|
<< Phrases::SubError << error.message() << Phrases::End;
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
result = ip;
|
result = ip;
|
||||||
|
@ -69,7 +69,7 @@ template <> inline void convertValue(const std::multimap<std::string, std::strin
|
||||||
try {
|
try {
|
||||||
result = stringToNumber<unsigned short>(value);
|
result = stringToNumber<unsigned short>(value);
|
||||||
} catch (const ConversionException &) {
|
} catch (const ConversionException &) {
|
||||||
cerr << Phrases::Error << "Specified number \"" << value << "\" for key \"" << key << "\" is invalid." << Phrases::End;
|
cerr << Phrases::ErrorMessage << "Specified number \"" << value << "\" for key \"" << key << "\" is invalid." << Phrases::End;
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ template <> inline void convertValue(const std::multimap<std::string, std::strin
|
||||||
try {
|
try {
|
||||||
result = value;
|
result = value;
|
||||||
} catch (const regex_error &e) {
|
} catch (const regex_error &e) {
|
||||||
cerr << Phrases::Error << "Specified regex \"" << value << "\" for key \"" << key << "\" is invalid: " << Phrases::End;
|
cerr << Phrases::ErrorMessage << "Specified regex \"" << value << "\" for key \"" << key << "\" is invalid: " << Phrases::End;
|
||||||
cerr << e.what() << '\n';
|
cerr << e.what() << '\n';
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue