mirror of
https://github.com/NixOS/nix.git
synced 2025-11-12 13:36:02 +01:00
bugfix in getInteger(const nlohmann::json &) and add bounds checks
improve error messages, too
This commit is contained in:
parent
2ec1303286
commit
788be3f964
5 changed files with 54 additions and 15 deletions
|
|
@ -92,9 +92,18 @@ const nlohmann::json::string_t & getString(const nlohmann::json & value)
|
|||
return ensureType(value, nlohmann::json::value_t::string).get_ref<const nlohmann::json::string_t &>();
|
||||
}
|
||||
|
||||
const nlohmann::json::number_integer_t & getInteger(const nlohmann::json & value)
|
||||
const nlohmann::json::number_unsigned_t & getUnsigned(const nlohmann::json & value)
|
||||
{
|
||||
return ensureType(value, nlohmann::json::value_t::number_integer).get_ref<const nlohmann::json::number_integer_t &>();
|
||||
if (auto ptr = value.get<const nlohmann::json::number_unsigned_t *>()) {
|
||||
return *ptr;
|
||||
}
|
||||
const char * typeName = value.type_name();
|
||||
if (typeName == nlohmann::json(0).type_name()) {
|
||||
typeName = value.is_number_float() ? "floating point number" : "signed integral number";
|
||||
}
|
||||
throw Error(
|
||||
"Expected JSON value to be an unsigned integral number but it is of type '%s': %s",
|
||||
typeName, value.dump());
|
||||
}
|
||||
|
||||
const nlohmann::json::boolean_t & getBoolean(const nlohmann::json & value)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue