Skip to content

Commit

Permalink
fable: Fix use of nlohmann::detail namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
cassava committed Apr 22, 2024
1 parent 1b874bb commit b0f57ea
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions fable/include/fable/conf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class Conf {
[[nodiscard]] T get() const {
try {
return data_.get<T>();
} catch (nlohmann::detail::type_error&) {
} catch (Json::type_error&) {
throw_wrong_type();
}
}
Expand All @@ -180,9 +180,9 @@ class Conf {
[[nodiscard]] T get(const std::string& key) const {
try {
return data_.at(key).get<T>();
} catch (nlohmann::detail::out_of_range&) {
} catch (Json::out_of_range&) {
throw_missing(key);
} catch (nlohmann::detail::type_error&) {
} catch (Json::type_error&) {
throw_wrong_type(key);
}
}
Expand All @@ -191,9 +191,9 @@ class Conf {
[[nodiscard]] T get(const JsonPointer& key) const {
try {
return data_.at(key).get<T>();
} catch (nlohmann::detail::out_of_range&) {
} catch (Json::out_of_range&) {
throw_missing(key.to_string());
} catch (nlohmann::detail::type_error&) {
} catch (Json::type_error&) {
throw_wrong_type(key.to_string());
}
}
Expand All @@ -214,7 +214,7 @@ class Conf {
}
try {
return data_.at(key).get<T>();
} catch (nlohmann::detail::type_error&) {
} catch (Json::type_error&) {
throw_wrong_type(key);
}
}
Expand All @@ -223,9 +223,9 @@ class Conf {
[[nodiscard]] T get_or(const JsonPointer& key, T def) const {
try {
return data_.at(key).get<T>();
} catch (nlohmann::detail::out_of_range&) {
} catch (Json::out_of_range&) {
return def;
} catch (nlohmann::detail::type_error&) {
} catch (Json::type_error&) {
throw_wrong_type(key.to_string());
}
}
Expand All @@ -252,7 +252,7 @@ class Conf {
void with(const JsonPointer& key, std::function<void(const T&)> fn) const {
try {
fn(get<T>(key));
} catch (nlohmann::detail::out_of_range&) {
} catch (Json::out_of_range&) {
return;
}
}
Expand All @@ -278,9 +278,9 @@ class Conf {
void try_from(const JsonPointer& key, T& val) const {
try {
val = data_.at(key).get<T>();
} catch (nlohmann::detail::out_of_range& e) {
} catch (Json::out_of_range& e) {
return;
} catch (nlohmann::detail::type_error& e) {
} catch (Json::type_error& e) {
throw_wrong_type(key.to_string());
}
}
Expand Down
1 change: 0 additions & 1 deletion fable/include/fable/fable_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ namespace fable {
// from json.hpp
using Json = nlohmann::json;
using JsonPointer = nlohmann::json_pointer<std::string>;
using JsonType = nlohmann::detail::value_t;

// from conf.hpp
class Conf;
Expand Down
2 changes: 1 addition & 1 deletion fable/include/fable/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ using JsonPointer = nlohmann::json_pointer<std::string>;
* This makes it easier to talk/write about operations that deal on the
* underlying type that is stored in a Json value.
*/
using JsonType = nlohmann::detail::value_t;
using JsonType = nlohmann::json::value_t;

/**
* Return a string representation of a JSON type.
Expand Down
5 changes: 3 additions & 2 deletions fable/src/fable/conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Conf::Conf(std::string file) : file_(std::move(file)) {
bool Conf::has(const JsonPointer& key) const {
try {
return data_.contains(key);
} catch (nlohmann::detail::exception&) {
} catch (Json::exception&) {
// Exception is probably one of json::out_of_range or json::parse_error.
return false;
}
Expand Down Expand Up @@ -82,9 +82,10 @@ size_t Conf::erase(const JsonPointer& key) {
if (parent.empty()) {
n += erase(key.parent_pointer());
}
} catch (nlohmann::detail::exception&) {
} catch (Json::exception&) {
// Exception is probably one of json::out_of_range or json::parse_error.
// If the key doesn't exist, then there is nothing we need to delete.
std::ignore;
}
return n;
}
Expand Down

0 comments on commit b0f57ea

Please sign in to comment.