Skip to content

Commit d3e2914

Browse files
committed
refactor: cleanup code and modernize error handling
1 parent 339c673 commit d3e2914

1 file changed

Lines changed: 3 additions & 9 deletions

File tree

src/easy_phi.hpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <variant>
99
#include <unordered_map>
1010
#include <cmath>
11-
#include <stdarg.h>
1211
#include <iostream>
1312
#include <fstream>
1413
#include <algorithm>
@@ -160,7 +159,7 @@ void checkBoolAndThrow(bool condition, const std::string& msg, const std::string
160159
if (prefix.empty()) {
161160
throw std::runtime_error(msg);
162161
} else {
163-
throw std::runtime_error(prefix + ": " + msg);
162+
throw std::runtime_error(std::format("{}: {}", prefix, msg));
164163
}
165164
}
166165
}
@@ -525,9 +524,7 @@ struct ThreadSafeQueue {
525524
};
526525

527526
struct JsonNode {
528-
enum class EnumType {
529-
String, Number, Bool, Array, Object, Null
530-
};
527+
enum class EnumType { String, Number, Bool, Array, Object, Null };
531528

532529
EnumType type;
533530
std::variant<
@@ -732,8 +729,7 @@ struct JsonNode {
732729

733730
static JsonNode Parse(StringReader& reader) {
734731
/* !docs
735-
Parse a JSON string into a JsonNode.
736-
The result is a pair of a boolean indicating success and a string containing an error message if failed.
732+
It will throw if parsing failed.
737733
*/
738734

739735
auto failed = [&](const std::string& err) {
@@ -11677,8 +11673,6 @@ void main() {
1167711673
}
1167811674
};
1167911675

11680-
#undef failed
11681-
1168211676
} // namespace easy_phi
1168311677

1168411678
#ifdef EASY_PHI_TEXT_RENDERER

0 commit comments

Comments
 (0)