{"record":{"id":"839347bf6825f21f","repo":"larksuite/cli","slug":"expected-positive-integer","errorCode":null,"errorMessage":"expected positive integer","messagePattern":"expected positive integer","errorType":"validation","errorClass":"ArithmeticError","httpStatus":null,"severity":"error","filePath":"skills/lark-slides/scripts/sxsd_validator.py","lineNumber":496,"sourceCode":"    }\n    if attr is not None:\n        result[\"attr\"] = attr\n    return result\n\n\ndef builtin_scalar_value(type_name: str, value: str) -> Decimal | str | bool:\n    if type_name in {\"string\", \"anyURI\"}:\n        return value\n    if type_name == \"boolean\":\n        if value not in {\"true\", \"false\", \"1\", \"0\"}:\n            raise ValueError(\"expected boolean\")\n        return value in {\"true\", \"1\"}\n    if type_name in {\"integer\", \"positiveInteger\", \"nonNegativeInteger\"}:\n        if re.fullmatch(r\"[+-]?\\d+\", value) is None:\n            raise ValueError(\"expected integer\")\n        number = Decimal(value)\n        if type_name == \"positiveInteger\" and number <= 0:\n            raise ArithmeticError(\"expected positive integer\")\n        if type_name == \"nonNegativeInteger\" and number < 0:\n            raise ArithmeticError(\"expected non-negative integer\")\n        return number\n    if type_name in {\"double\", \"decimal\"}:\n        lexical_value = value.strip(\" \\t\\n\\r\")\n        decimal_pattern = r\"[+-]?(?:[0-9]+(?:\\.[0-9]*)?|\\.[0-9]+)\"\n        double_pattern = decimal_pattern + r\"(?:[eE][+-]?[0-9]+)?\"\n        expected_pattern = double_pattern if type_name == \"double\" else decimal_pattern\n        if re.fullmatch(expected_pattern, lexical_value) is None:\n            raise ValueError(f\"expected {type_name}\")\n        try:\n            number = Decimal(lexical_value)\n        except InvalidOperation as error:\n            raise ValueError(f\"expected {type_name}\") from error\n        if not math.isfinite(float(number)):\n            raise ValueError(f\"expected finite {type_name}\")\n        return number\n    return value","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/skills/lark-slides/scripts/sxsd_validator.py#L478-L514","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Change the value so it is at least 1 (e.g. '1' instead of '0' or '-3').","If 0 is legitimate for the field, change the schema type to nonNegativeInteger or int.","Check the code that generates the attribute for arithmetic producing zero/negative values (e.g. index-1, size-offset) and clamp or guard it.","Re-run the validator to confirm the fix."],"exampleFix":"// before\n<slide size=\"0\"/>\n// after\n<slide size=\"1\"/>","handlingStrategy":"validation","validationCode":"def is_positive_integer(text):\n    import re\n    return bool(re.fullmatch(r'[+-]?\\d+', text)) and int(text) > 0\n\nif not is_positive_integer(attr_value):\n    raise ValueError(f'attribute must be a positive integer, got {attr_value!r}')","typeGuard":"def as_positive_int(text):\n    try:\n        n = int(text)\n    except ValueError:\n        return None\n    return n if n > 0 else None","tryCatchPattern":"try:\n    value = scalar_value_for_type('positiveInteger', raw)\nexcept ArithmeticError as e:\n    print(f'repair value: {e}')  # set to >= 1","preventionTips":["Clamp counts/sizes to max(1, n) at the producer before serialization.","Never use 0 as a sentinel for positive-typed attributes.","Add a unit check on generated XML for positiveInteger fields."],"tags":["python","xsd","validation"],"backgroundTag":"xsd-positive-integer-violation","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}