{"record":{"id":"39f7472eba674825","repo":"iflytek/astron-agent","slug":"file-invalid-error","errorCode":"FILE_INVALID_ERROR","errorMessage":"Unsupported file category","messagePattern":"Unsupported file category","errorType":"error_code","errorClass":"CustomException","httpStatus":null,"severity":"error","filePath":"core/workflow/configs/app_config.py","lineNumber":103,"sourceCode":"        extension: str,\n        file_size: int,\n        category: Optional[str] = None,\n    ) -> None:\n        \"\"\"\n        Validate if the file is valid.\n\n        :param extension: The extension of the file\n        :param file_size: The size of the file\n        :param category: The category of the file\n        :raises CustomException: If the file is not valid\n        \"\"\"\n        if category is None:\n            cat = self._find_category_by_ext(extension)\n        else:\n            cat = self._get_category(category)\n\n        if cat is None:\n            raise CustomException(\n                err_code=CodeEnum.FILE_INVALID_ERROR,\n                err_msg=\"Unsupported file category\",\n                cause_error=\"File type does not meet requirements\",\n            )\n\n        if extension not in cat.extensions:\n            raise CustomException(\n                err_code=CodeEnum.FILE_INVALID_ERROR,\n                err_msg=\"Error: Unsupported file extension\",\n                cause_error=f\"File type does not meet requirements. User uploaded file type: {extension}, allowed file types: {cat.extensions}\",\n            )\n\n        if file_size > cat.size:\n            raise CustomException(\n                err_code=CodeEnum.FILE_INVALID_ERROR,\n                err_msg=\"Error: File size exceeds limit\",\n                cause_error=f\"File size: {file_size}, exceeds {cat.size} bytes\",\n            )","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/configs/app_config.py#L85-L121","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Normalize the file extension (lowercase, strip leading '.') and pass it so _find_category_by_ext can resolve a category","Add the missing category or extension mapping to the file config in app_config.py / config file","Check the configured category names and pass an exact existing category value","Reject the upload client-side with an allowed-types list before sending"],"exampleFix":"// before\nconfig.is_valid(file_ext.upper(), size, category=\"Docs\")  # unknown category\n// after\nconfig.is_valid(file_ext.lower().lstrip('.'), size, category=\"docs\")","handlingStrategy":"validation","validationCode":"ext = filename.rsplit('.', 1)[-1].lower()\nif not config.has_category(category) and not config.has_extension(ext):\n    raise UploadRejected(f\"unsupported file category/extension: {category or ext}\")","typeGuard":null,"tryCatchPattern":"try:\n    file_config.is_valid(ext, size, category=category)\nexcept CustomException as e:\n    if e.err_code == CodeEnum.FILE_INVALID_ERROR:\n        return reject_upload(allowed=config.list_categories())\n    raise","preventionTips":["Normalize extensions (lowercase, strip dot) before validation","Keep category/extension mappings consistent across environments","Expose allowed categories to the frontend for pre-upload filtering","Add new file types to config before enabling them in the UI"],"tags":["file-upload","validation","configuration"],"backgroundTag":"invalid-argument-value","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}