larksuite/cli · error · ValueError
expected {type_name}
Error message
expected {type_name} What it means
This ValueError is raised by builtin_scalar_value when a value typed xsd:double or xsd:decimal fails the XSD lexical pattern for that type. decimal allows only plain decimal notation; double additionally allows scientific exponent notation. The message interpolates the offending type name.
Source
Thrown at skills/lark-slides/scripts/sxsd_validator.py:506
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
def scalar_value_for_type(
type_name: str,
value: str,
model: SchemaModel,
resolving: set[str] | None = None,
) -> Decimal | str | bool:
resolving = resolving or set()
if type_name in resolving:View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Rewrite the value using '.' as the decimal separator and no thousands separators.
- For xsd:decimal, remove the exponent (convert '1.5e3' to '1500').
- For special values use the appropriate type or sentinel allowed by the schema instead of INF/NaN.
- Fix the serializer to use invariant culture / non-locale number formatting.
Example fix
// before <scale factor="1,5e2"/> <!-- decimal with comma+exponent --> // after <scale factor="150"/>
Defensive patterns
Strategy: validation
Validate before calling
import re
double_re = re.compile(r'[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?')
decimal_re = re.compile(r'[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)')
assert decimal_re.fullmatch('1.5') is not None # no commas, no exponent for decimal Type guard
def is_xsd_number(text, allow_exponent=False):
import re
base = r'[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)'
pat = base + (r'(?:[eE][+-]?[0-9]+)?' if allow_exponent else '')
return re.fullmatch(pat, text.strip()) is not None Try / catch
try:
value = scalar_value_for_type('decimal', raw)
except ValueError as e:
print(f'fix lexical form (use "1.5" style): {e}') Prevention
- Serialize numbers with invariant/POSIX locale (never comma decimal separators).
- Avoid INF/NaN literals in XSD numeric fields.
- Use exponent-free formatting for xsd:decimal values.
When it happens
Trigger: Calling scalar_value_for_type with type_name 'double' or 'decimal' and values like '1,5' (comma decimal separator), 'NaN', 'INF', '1e5' for decimal (exponent not allowed), '1.2.3', or whitespace-embedded numbers.
Common situations: Locale-formatting bugs exporting '1,5' instead of '1.5'; XML producers emitting INF/NaN for doubles where XSD forbids them; scientific notation used in decimal fields; empty or placeholder values.
Related errors
- expected positive integer
- expected non-negative integer
- expected finite {type_name}
- unsupported complemented XSD character class \{escaped} insi
- --header-scan-rows must be at least 1
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/b75b38cea2e84ff9.
Report an issue: GitHub.