Skip to content

Commit b0f57ea

Browse files
committed
fable: Fix use of nlohmann::detail namespace
1 parent 1b874bb commit b0f57ea

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

fable/include/fable/conf.hpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class Conf {
166166
[[nodiscard]] T get() const {
167167
try {
168168
return data_.get<T>();
169-
} catch (nlohmann::detail::type_error&) {
169+
} catch (Json::type_error&) {
170170
throw_wrong_type();
171171
}
172172
}
@@ -180,9 +180,9 @@ class Conf {
180180
[[nodiscard]] T get(const std::string& key) const {
181181
try {
182182
return data_.at(key).get<T>();
183-
} catch (nlohmann::detail::out_of_range&) {
183+
} catch (Json::out_of_range&) {
184184
throw_missing(key);
185-
} catch (nlohmann::detail::type_error&) {
185+
} catch (Json::type_error&) {
186186
throw_wrong_type(key);
187187
}
188188
}
@@ -191,9 +191,9 @@ class Conf {
191191
[[nodiscard]] T get(const JsonPointer& key) const {
192192
try {
193193
return data_.at(key).get<T>();
194-
} catch (nlohmann::detail::out_of_range&) {
194+
} catch (Json::out_of_range&) {
195195
throw_missing(key.to_string());
196-
} catch (nlohmann::detail::type_error&) {
196+
} catch (Json::type_error&) {
197197
throw_wrong_type(key.to_string());
198198
}
199199
}
@@ -214,7 +214,7 @@ class Conf {
214214
}
215215
try {
216216
return data_.at(key).get<T>();
217-
} catch (nlohmann::detail::type_error&) {
217+
} catch (Json::type_error&) {
218218
throw_wrong_type(key);
219219
}
220220
}
@@ -223,9 +223,9 @@ class Conf {
223223
[[nodiscard]] T get_or(const JsonPointer& key, T def) const {
224224
try {
225225
return data_.at(key).get<T>();
226-
} catch (nlohmann::detail::out_of_range&) {
226+
} catch (Json::out_of_range&) {
227227
return def;
228-
} catch (nlohmann::detail::type_error&) {
228+
} catch (Json::type_error&) {
229229
throw_wrong_type(key.to_string());
230230
}
231231
}
@@ -252,7 +252,7 @@ class Conf {
252252
void with(const JsonPointer& key, std::function<void(const T&)> fn) const {
253253
try {
254254
fn(get<T>(key));
255-
} catch (nlohmann::detail::out_of_range&) {
255+
} catch (Json::out_of_range&) {
256256
return;
257257
}
258258
}
@@ -278,9 +278,9 @@ class Conf {
278278
void try_from(const JsonPointer& key, T& val) const {
279279
try {
280280
val = data_.at(key).get<T>();
281-
} catch (nlohmann::detail::out_of_range& e) {
281+
} catch (Json::out_of_range& e) {
282282
return;
283-
} catch (nlohmann::detail::type_error& e) {
283+
} catch (Json::type_error& e) {
284284
throw_wrong_type(key.to_string());
285285
}
286286
}

fable/include/fable/fable_fwd.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ namespace fable {
3434
// from json.hpp
3535
using Json = nlohmann::json;
3636
using JsonPointer = nlohmann::json_pointer<std::string>;
37-
using JsonType = nlohmann::detail::value_t;
3837

3938
// from conf.hpp
4039
class Conf;

fable/include/fable/json.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ using JsonPointer = nlohmann::json_pointer<std::string>;
7575
* This makes it easier to talk/write about operations that deal on the
7676
* underlying type that is stored in a Json value.
7777
*/
78-
using JsonType = nlohmann::detail::value_t;
78+
using JsonType = nlohmann::json::value_t;
7979

8080
/**
8181
* Return a string representation of a JSON type.

fable/src/fable/conf.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Conf::Conf(std::string file) : file_(std::move(file)) {
4949
bool Conf::has(const JsonPointer& key) const {
5050
try {
5151
return data_.contains(key);
52-
} catch (nlohmann::detail::exception&) {
52+
} catch (Json::exception&) {
5353
// Exception is probably one of json::out_of_range or json::parse_error.
5454
return false;
5555
}
@@ -82,9 +82,10 @@ size_t Conf::erase(const JsonPointer& key) {
8282
if (parent.empty()) {
8383
n += erase(key.parent_pointer());
8484
}
85-
} catch (nlohmann::detail::exception&) {
85+
} catch (Json::exception&) {
8686
// Exception is probably one of json::out_of_range or json::parse_error.
8787
// If the key doesn't exist, then there is nothing we need to delete.
88+
std::ignore;
8889
}
8990
return n;
9091
}

0 commit comments

Comments
 (0)