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:
fl0l0u committed 2026-11-15 22:02:29 +00:00
1 parent 5e2e596644
commit b9ecbde0d6
6 files changed
+23 -14

No files matched your search

+7
View File
@@ -901,6 +901,13 @@ public:
* to overflow a dump's or a destructor's stack on the way there. */
static Json parse_container(std::string_view text, bool* over = nullptr,
bool* deep = nullptr);
/* The refusal message behind `over`/`deep`: one wording for all callers, so the bound and
* the phrase that names it live together instead of being re-typed at each refuse site
* (six near-copies had drifted). The phrase for whichever bound tripped. */
static const char* bound_why(bool over, bool deep);
/* The container read's own bounds, for a caller that states them in its refusal. */
static constexpr int64_t kContainerBudget = 1LL << 24;
static constexpr int kContainerDepth = 256;
private:
using difference_type = std::ptrdiff_t;