larksuite/cli · error · ArithmeticError
expected non-negative integer
Error message
expected non-negative integer
What it means
This ArithmeticError is raised by builtin_scalar_value when a value typed xsd:nonNegativeInteger is negative. XSD allows 0 but forbids negative integers for this type. The validator checks the value space after confirming the lexical form is a valid integer.
Source
Thrown at skills/lark-slides/scripts/sxsd_validator.py:498
result["attr"] = attr
return result
def builtin_scalar_value(type_name: str, value: str) -> Decimal | str | bool:
if type_name in {"string", "anyURI"}:
return value
if type_name == "boolean":
if value not in {"true", "false", "1", "0"}:
raise ValueError("expected boolean")
return value in {"true", "1"}
if type_name in {"integer", "positiveInteger", "nonNegativeInteger"}:
if re.fullmatch(r"[+-]?\d+", value) is None:
raise ValueError("expected integer")
number = Decimal(value)
if type_name == "positiveInteger" and number <= 0:
raise ArithmeticError("expected positive integer")
if type_name == "nonNegativeInteger" and number < 0:
raise ArithmeticError("expected non-negative integer")
return number
if type_name in {"double", "decimal"}:
lexical_value = value.strip(" \t\n\r")
decimal_pattern = r"[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)"
double_pattern = decimal_pattern + r"(?:[eE][+-]?[0-9]+)?"
expected_pattern = double_pattern if type_name == "double" else decimal_pattern
if re.fullmatch(expected_pattern, lexical_value) is None:
raise ValueError(f"expected {type_name}")
try:
number = Decimal(lexical_value)
except InvalidOperation as error:
raise ValueError(f"expected {type_name}") from error
if not math.isfinite(float(number)):
raise ValueError(f"expected finite {type_name}")
return number
return value
View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Replace the negative value with 0 or a positive integer as appropriate for the field.
- Verify upstream producer logic cannot emit negative values for this attribute (guard/clamp at generation).
- If negative values are meaningful, change the schema type to xsd:integer.
- Re-run the validator to confirm.
Example fix
// before offset="-2" // after offset="0"
Defensive patterns
Strategy: validation
Validate before calling
def is_non_negative_integer(text):
import re
return bool(re.fullmatch(r'[+-]?\d+', text)) and int(text) >= 0
if not is_non_negative_integer(attr_value):
raise ValueError(f'attribute must be >= 0, got {attr_value!r}') Type guard
def as_non_negative_int(text):
try:
n = int(text)
except ValueError:
return None
return n if n >= 0 else None Try / catch
try:
value = scalar_value_for_type('nonNegativeInteger', raw)
except ArithmeticError as e:
print(f'clamp to 0: {e}') Prevention
- Clamp computed offsets with max(0, n) before writing XML.
- Avoid signed underflow when subtracting lengths/offsets in producers.
- Validate generated XML attributes in CI with the schema validator.
When it happens
Trigger: Calling scalar_value_for_type with type_name='nonNegativeInteger' and a value such as '-1', '-100', or '-0x...' style negative literals (after lexical integer check passes).
Common situations: Generated slides XML where an offset, count, or dimension went negative due to unsigned arithmetic underflow in the producer; subtracting more than available; copy-paste edits introducing minus signs.
Related errors
- expected positive integer
- Range needs a maximum column: {range_ref}
- Range needs a maximum row: {range_ref}
- Row must be >= 1: {row}
- expected boolean
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/1a9059fa9d0771b8.
Report an issue: GitHub.