diff options
author | MacroFake <falke.marco@gmail.com> | 2022-07-18 11:13:22 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-07-18 11:31:36 +0200 |
commit | fae5ce8795080018875227aee8613677f92e99ce (patch) | |
tree | 4b54dad97fc8c0847c81e7ed3945d404b3c4f945 /src/univalue/include | |
parent | fafab147e7ff41ab1b961349f20a364f6bf847d2 (diff) |
univalue: Return more detailed type check error messages
Diffstat (limited to 'src/univalue/include')
-rw-r--r-- | src/univalue/include/univalue.h | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/univalue/include/univalue.h b/src/univalue/include/univalue.h index b665954927..dff544f96f 100644 --- a/src/univalue/include/univalue.h +++ b/src/univalue/include/univalue.h @@ -106,6 +106,7 @@ private: std::vector<std::string> keys; std::vector<UniValue> values; + void checkType(const VType& expected) const; bool findKey(const std::string& key, size_t& retIdx) const; void writeArray(unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const; void writeObject(unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const; @@ -130,7 +131,7 @@ public: template <class It> void UniValue::push_backV(It first, It last) { - if (typ != VARR) throw std::runtime_error{"JSON value is not an array as expected"}; + checkType(VARR); values.insert(values.end(), first, last); } @@ -138,9 +139,7 @@ template <typename Int> Int UniValue::getInt() const { static_assert(std::is_integral<Int>::value); - if (typ != VNUM) { - throw std::runtime_error("JSON value is not an integer as expected"); - } + checkType(VNUM); Int result; const auto [first_nonmatching, error_condition] = std::from_chars(val.data(), val.data() + val.size(), result); if (first_nonmatching != val.data() + val.size() || error_condition != std::errc{}) { |