diff --git a/src/config.cc b/src/config.cc index 629c144df889d10f7e3b711d66df94163f1ae83e..04e4ebda4768679b98afdbe0b278a3dc4ac2429d 100644 --- a/src/config.cc +++ b/src/config.cc @@ -21,12 +21,14 @@ uint32_t ConfigMap::Get<uint32_t>(const std::string &k) { ValueType value = at(k); try { return value.asUInt(); - } catch (std::exception &e) { - LOG(DEBUG) << "Value '" << value.asString() << "' not natively convertible to uint32"; + } catch (std::exception &e1) { + const auto str_val = value.asString(); + LOG(DEBUG) << "Key: " << k << "| Value '" << str_val << "' | Exception: " << e1.what(); + LOG(DEBUG) << "Recovering by converting to uint32_t"; try { - return static_cast<uint32_t>(std::stoul(value.asString())); - } catch (std::exception &e) { - LOG(ERROR) << "Configuration error with key: '" << k << "'"; + return static_cast<uint32_t>(std::stoul(str_val)); + } catch (std::exception &e2) { + LOG(ERROR) << "Conversion of '" << str_val << "' failed with exception: " << e2.what(); throw; } } @@ -37,12 +39,14 @@ uint64_t ConfigMap::Get<uint64_t>(const std::string &k) { ValueType value = at(k); try { return value.asUInt64(); - } catch (std::exception &e) { - LOG(DEBUG) << "Value '" << value.asString() << "' not natively convertible to uint64"; + } catch (std::exception &e1) { + const auto str_val = value.asString(); + LOG(DEBUG) << "Key: " << k << "| Value '" << str_val << "' | Exception: " << e1.what(); + LOG(DEBUG) << "Recovering by converting to uint64_t"; try { - return static_cast<uint64_t>(std::stoul(value.asString())); - } catch (std::exception &e) { - LOG(ERROR) << "Configuration error with key: '" << k << "'"; + return static_cast<uint64_t>(std::stoul(str_val)); + } catch (std::exception &e2) { + LOG(ERROR) << "Conversion of '" << str_val << "' failed with exception: " << e2.what(); throw; } } @@ -53,12 +57,14 @@ int ConfigMap::Get<int>(const std::string &k) { ValueType value = at(k); try { return value.asInt(); - } catch (std::exception &e) { - LOG(DEBUG) << "Value '" << value.asString() << "' not natively convertible to integer"; + } catch (std::exception &e1) { + const auto str_val = value.asString(); + LOG(DEBUG) << "Key: " << k << "| Value '" << str_val << "' | Exception: " << e1.what(); + LOG(DEBUG) << "Recovering by converting to int"; try { - return std::stoi(value.asString()); - } catch (std::exception &e) { - LOG(ERROR) << "Configuration error with key: '" << k << "'"; + return static_cast<int>(std::stoul(str_val)); + } catch (std::exception &e2) { + LOG(ERROR) << "Conversion of '" << str_val << "' failed with exception: " << e2.what(); throw; } }