Archived
util: one wording for the bounded read's refusal
The refuse sites that read a container file all re-typed the same two-branch message -- over ? "carries far too many values" : "nests far too deep" -- six times, and the copies had already drifted: gen_config said "carries far too many JSON values", xstats "far too many values", tokenizer_config "it does not parse" for the discarded case. The bounds themselves (2^24, 256) were also spelled as literals in tokenizer_json's refusal, so a bound change there would make its message a lie. Json::bound_why(over, deep) is the phrase, owned beside the read that sets the flags, and the two bounds are exported as kContainerBudget / kContainerDepth so the one message that states them reads them from the constants. Every refuse site now calls it; the wording is one, the numbers cannot drift. No behaviour change -- the same flags map to the same failure paths, only the text they print is unified.
This commit is contained in:
1 parent
5e2e596644
commit
b9ecbde0d6
6 files changed
+23
-14
No files matched your search
+7
-1
@@ -251,12 +251,18 @@ Json Json::parse_bounded(std::string_view text, int64_t budget, int max_depth, b
|
||||
|
||||
Json Json::parse_container(std::string_view text, bool* over, bool* deep) {
|
||||
bool o = false, d = false;
|
||||
Json j = parse_bounded(text, 1LL << 24, 256, &o, &d);
|
||||
Json j = parse_bounded(text, kContainerBudget, kContainerDepth, &o, &d);
|
||||
if (over) *over = o;
|
||||
if (deep) *deep = d;
|
||||
return j;
|
||||
}
|
||||
|
||||
const char* Json::bound_why(bool over, bool deep) {
|
||||
return over ? "carries far too many values"
|
||||
: deep ? "nests far too deep"
|
||||
: "is not valid JSON";
|
||||
}
|
||||
|
||||
Json Json::parse(std::string_view text) { return parse(text, nullptr, true, false); }
|
||||
|
||||
Json Json::parse(std::istream& in) {
|
||||
|
||||
Reference in new issue
Block a user