iflytek/astron-agent · error · ValueError

Invalid size expression

Error message

Invalid size expression: {v}

What it means

parse_size raises ValueError('Invalid size expression: {v}') when a string size looks like a multiplication expression (contains '*') but one or more '*'-separated parts are not valid integers. Used to turn config strings like '512*1024*1024' into byte counts for file size limits.

Solutions

  1. Write the size as a pure multiplication of integers, e.g. '512*1024*1024', with no units or spaces
  2. Use a plain integer byte value (e.g. '1073741824') instead of an expression
  3. Quote the value in YAML so it is parsed as a string with the expected format

Example fix

// before
file_max_size: 1024*1024MB
// after
file_max_size: 1024*1024*1024
Defensive patterns

Strategy: validation

Validate before calling

import re
SIZE_EXPR = re.compile(r"^\d+(\*\d+)*$")
if not SIZE_EXPR.match(str(value)):
    raise ValueError(f"size must be digits or N*N multiplication, got {value!r}")

Try / catch

try:
    limit = parse_size(raw)
except ValueError as e:
    logger.error("bad size expression in config: %s", e)
    raise SystemExit(2)

Prevention

When it happens

Trigger: Config value like '512x1024' or '10 * 1024MB' or '1024**1024' where splitting on '*' yields non-numeric parts; whitespace-embedded or unit-suffixed expressions inside a '*' expression.

Common situations: Operator writes '1*1024*1024 MB' or '100*KB' in the size config; YAML unquoted value mangled; copy-paste from docs with units included.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/a7249b4be6d1bc33. Report an issue: GitHub.

Appendix: source

Thrown at core/workflow/configs/app_config.py:46

    @classmethod
    def parse_size(cls, v: Any) -> int:
        """
        Parse the size of the file category.

        :param v: The size of the file category
        :return: The size of the file category
        :raises ValueError: If the size of the file category is invalid
        """
        if isinstance(v, str):
            if "*" in v:
                try:
                    parts = [int(x) for x in v.split("*")]
                    result = 1
                    for p in parts:
                        result *= p
                    return result
                except ValueError:
                    raise ValueError(f"Invalid size expression: {v}")
            if v.isdigit():
                return int(v)
        if isinstance(v, (int, float)):
            return int(v)
        raise ValueError(f"Cannot convert size: {v!r}")


class FileConfig(BaseSettings):
    """
    File configuration model.

    This model represents the file configuration with its categories.
    :param categories: The categories of the file configuration
    """

    model_config = {"env_prefix": "", "case_sensitive": False}
    categories: List[FileCategory] = Field(default_factory=list, alias="FILE_POLICY")

View on GitHub (pinned to 5e758547a8)