iflytek/astron-agent · error · CustomException

FILE_INVALID_ERROR

FILE_INVALID_ERROR

Error message

Unsupported file category

What it means

FileConfig.is_valid raises CustomException FILE_INVALID_ERROR when the file category (explicit or inferred from extension) cannot be found in the configured category table. It is the first gate of upload validation: without a recognized category, extension and size checks cannot proceed.

Solutions

  1. Normalize the file extension (lowercase, strip leading '.') and pass it so _find_category_by_ext can resolve a category
  2. Add the missing category or extension mapping to the file config in app_config.py / config file
  3. Check the configured category names and pass an exact existing category value
  4. Reject the upload client-side with an allowed-types list before sending

Example fix

// before
config.is_valid(file_ext.upper(), size, category="Docs")  # unknown category
// after
config.is_valid(file_ext.lower().lstrip('.'), size, category="docs")
Defensive patterns

Strategy: validation

Validate before calling

ext = filename.rsplit('.', 1)[-1].lower()
if not config.has_category(category) and not config.has_extension(ext):
    raise UploadRejected(f"unsupported file category/extension: {category or ext}")

Try / catch

try:
    file_config.is_valid(ext, size, category=category)
except CustomException as e:
    if e.err_code == CodeEnum.FILE_INVALID_ERROR:
        return reject_upload(allowed=config.list_categories())
    raise

Prevention

When it happens

Trigger: Calling is_valid with a category name not present in the config categories, or an extension not mapped by _find_category_by_ext; category key renamed in config while callers still pass the old name.

Common situations: New upload type (e.g. .dwg) not whitelisted in app config; category renamed from 'document' to 'docs' across environments; extension uppercase or with leading dot not normalized before lookup.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

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

        extension: str,
        file_size: int,
        category: Optional[str] = None,
    ) -> None:
        """
        Validate if the file is valid.

        :param extension: The extension of the file
        :param file_size: The size of the file
        :param category: The category of the file
        :raises CustomException: If the file is not valid
        """
        if category is None:
            cat = self._find_category_by_ext(extension)
        else:
            cat = self._get_category(category)

        if cat is None:
            raise CustomException(
                err_code=CodeEnum.FILE_INVALID_ERROR,
                err_msg="Unsupported file category",
                cause_error="File type does not meet requirements",
            )

        if extension not in cat.extensions:
            raise CustomException(
                err_code=CodeEnum.FILE_INVALID_ERROR,
                err_msg="Error: Unsupported file extension",
                cause_error=f"File type does not meet requirements. User uploaded file type: {extension}, allowed file types: {cat.extensions}",
            )

        if file_size > cat.size:
            raise CustomException(
                err_code=CodeEnum.FILE_INVALID_ERROR,
                err_msg="Error: File size exceeds limit",
                cause_error=f"File size: {file_size}, exceeds {cat.size} bytes",
            )

View on GitHub (pinned to 5e758547a8)