larksuite/cli · error · ArithmeticError

expected positive integer

Error message

expected positive integer

What it means

This ArithmeticError is raised by builtin_scalar_value in the XSD schema validator when an attribute or element value declared as xsd:positiveInteger parses as an integer but is zero or negative. XSD requires positiveInteger values to be >= 1. The validator enforces the lexical-then-value-space rules of the schema before coercion.

Source

Thrown at skills/lark-slides/scripts/sxsd_validator.py:496

    }
    if attr is not None:
        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

  1. Change the value so it is at least 1 (e.g. '1' instead of '0' or '-3').
  2. If 0 is legitimate for the field, change the schema type to nonNegativeInteger or int.
  3. Check the code that generates the attribute for arithmetic producing zero/negative values (e.g. index-1, size-offset) and clamp or guard it.
  4. Re-run the validator to confirm the fix.

Example fix

// before
<slide size="0"/>
// after
<slide size="1"/>
Defensive patterns

Strategy: validation

Validate before calling

def is_positive_integer(text):
    import re
    return bool(re.fullmatch(r'[+-]?\d+', text)) and int(text) > 0

if not is_positive_integer(attr_value):
    raise ValueError(f'attribute must be a positive integer, got {attr_value!r}')

Type guard

def as_positive_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('positiveInteger', raw)
except ArithmeticError as e:
    print(f'repair value: {e}')  # set to >= 1

Prevention

When it happens

Trigger: Calling scalar_value_for_type (or value_error_for_type) with type_name='positiveInteger' and a value like '0', '-5', or '-1' while validating a slides XML file against its schema.

Common situations: Hand-edited or generated OOXML/slides XML where a count, index, or size attribute was computed as 0 or a negative offset; templates produced by buggy export tools; users typing '0' expecting it to count as positive.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/839347bf6825f21f. Report an issue: GitHub.