iflytek/astron-agent · error · ValueError

Cannot convert size

Error message

Cannot convert size: {v!r}

What it means

parse_size raises ValueError('Cannot convert size: {v!r}') when the value is neither a '*' multiplication expression of integers, a digit string, nor an int/float. This is the final fallback guard for unparseable size configuration values.

Solutions

  1. Set the size as an integer number of bytes (int or digit-only string), e.g. 1073741824
  2. Use the supported 'N*N*...' multiplication form for readability, e.g. '1024*1024*1024'
  3. Validate the config file/environment value before startup with a regex like ^\d+(\*\d+)*$

Example fix

// before
max_file_size: "1GB"
// after
max_file_size: 1073741824
Defensive patterns

Strategy: validation

Validate before calling

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

Try / catch

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

Prevention

When it happens

Trigger: Passing a size as a string with units ('100MB'), a float-as-string ('10.5'), a list/dict, or None into a config field parsed by parse_size; nested config value of wrong type from Polaris/local file.

Common situations: Operator configures '1GB' or '512 MB' instead of bytes; JSON/YAML file provides a quoted float; environment variable interpolation yields an empty or non-numeric string.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

        :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")

    def _get_category(self, category: str) -> Optional[FileCategory]:
        """
        Get the category by its name.

        :param category: The name of the category

View on GitHub (pinned to 5e758547a8)