Skip to content

content_field_limit_error

Function: warmhub.content_field_limit_error

content_field_limit_error(path: str, value: str)

The message for an oversized content field, or None if it fits.

The single definition of the 64 KiB rule for this package: the validator below calls it on every declared string, every undeclared value, and every object key, so a caller measuring a value ahead of a write gets exactly the message the builder would have raised.

The first branch is a cheap reject: a string short enough under an upper bound on its encoded size cannot exceed the limit and never has to be encoded to find out. The bound is per unit of whatever len counts, and the two languages do not count the same thing. TypeScript’s value.length is UTF-16 code units and three bytes per unit is a sound ceiling. Python’s len is CODE POINTS, and an astral code point is one of them but four UTF-8 bytes, so three would be an under-estimate: 21_845 emoji measure 65_535 by that bound and 87_380 bytes in fact, and the limit would not be enforced on them at all. Four bytes per code point is the sound ceiling here. It short-circuits a slightly narrower band of inputs than TypeScript does, which costs an encode on strings between the two bounds and returns the same answer for every input.