Skip to content

Commit 5d581bb

Browse files
committed
fmt: Fix built-in types not formatting correctly in JSON, fix crashes when using invalid transform functions
1 parent 3a769a1 commit 5d581bb

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

generators/include/pl/formatters/formatter_json.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,14 @@ namespace pl::gen::fmt {
160160

161161
if (!pattern->getReadFormatterFunction().empty())
162162
formatString(pattern);
163-
else if (pattern->isSealed()) {
164-
auto literal = pattern->getValue();
163+
else {
164+
try {
165+
auto literal = pattern->getValue();
165166

166-
addLine(pattern->getVariableName(), formatLiteral(literal) + ",");
167+
addLine(pattern->getVariableName(), formatLiteral(literal) + ",");
168+
} catch (const std::exception &e) {
169+
addLine(pattern->getVariableName(), ::fmt::format("\"<error: {}>\",", e.what()));
170+
}
167171
}
168172
}
169173

generators/include/pl/formatters/formatter_yaml.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,13 @@ namespace pl::gen::fmt {
136136
if (!pattern->getReadFormatterFunction().empty())
137137
formatString(pattern);
138138
else {
139-
auto literal = pattern->getValue();
139+
try {
140+
auto literal = pattern->getValue();
140141

141-
addLine(pattern->getVariableName(), wolv::util::replaceStrings(formatLiteral(literal), "\n", " "));
142+
addLine(pattern->getVariableName(), wolv::util::replaceStrings(formatLiteral(literal), "\n", " "));
143+
} catch (std::exception &e) {
144+
addLine(pattern->getVariableName(), ::fmt::format("\"<Error: {}>\"", wolv::util::replaceStrings(e.what(), "\n", " ")));
145+
}
142146
}
143147
}
144148

0 commit comments

Comments
 (0)