{"record":{"id":"1a2e18f81f2d1a7a","repo":"deepset-ai/haystack","slug":"the-list-of-mime-types-cannot-be-empty-1a2e18","errorCode":null,"errorMessage":"The list of mime types cannot be empty.","messagePattern":"The list of mime types cannot be empty\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/routers/file_type_router.py","lineNumber":82,"sourceCode":"    ) -> None:\n        \"\"\"\n        Initialize the FileTypeRouter component.\n\n        :param mime_types:\n            A list of MIME types or regex patterns to classify the input files or byte streams.\n            (for example: `[\"text/plain\", \"audio/x-wav\", \"image/jpeg\"]`).\n\n        :param additional_mimetypes:\n            A dictionary containing the MIME type to add to the mimetypes package to prevent unsupported or non-native\n            packages from being unclassified.\n            (for example: `{\"application/vnd.openxmlformats-officedocument.wordprocessingml.document\": \".docx\"}`).\n\n        :param raise_on_failure:\n            If True, raises FileNotFoundError when a file path doesn't exist.\n            If False (default), only emits a warning when a file path doesn't exist.\n        \"\"\"\n        if not mime_types:\n            raise ValueError(\"The list of mime types cannot be empty.\")\n\n        if additional_mimetypes:\n            for mime, ext in additional_mimetypes.items():\n                mimetypes.add_type(mime, ext)\n\n        self.mime_type_patterns = []\n        for mime_type in mime_types:\n            try:\n                pattern = re.compile(mime_type)\n            except re.error as e:\n                raise ValueError(f\"Invalid MIME type or regex pattern '{mime_type}'.\") from e\n            self.mime_type_patterns.append(pattern)\n\n        # the actual output type is list[Union[Path, ByteStream]],\n        # but this would cause PipelineConnectError with Converters\n        component.set_output_types(\n            self,\n            unclassified=list[str | Path | ByteStream],","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/routers/file_type_router.py#L64-L100","documentation":"FileTypeRouter.__init__ raises this ValueError when the mime_types list is empty, since the router needs at least one MIME type pattern to define its output slots.","triggerScenarios":"FileTypeRouter(mime_types=[]) or a falsy mime_types argument (None, empty list).","commonSituations":"Empty configuration file; building the list dynamically from user input that was empty.","solutions":["Provide a non-empty list of MIME types, e.g. ['image/png', 'application/pdf']","Check upstream logic that builds the list before constructing the router"],"exampleFix":"# before\nrouter = FileTypeRouter(mime_types=[])\n# after\nrouter = FileTypeRouter(mime_types=[\"application/pdf\"])\n","handlingStrategy":"validation","validationCode":"if not mime_types:\n    raise ValueError(\"mime_types must be a non-empty list before constructing FileTypeRouter\")","typeGuard":"def has_mime_types(mime_types) -> bool:\n    return isinstance(mime_types, list) and len(mime_types) > 0","tryCatchPattern":"try:\n    router = FileTypeRouter(mime_types=mime_types)\nexcept ValueError as e:\n    if \"cannot be empty\" in str(e):\n        router = FileTypeRouter(mime_types=[\"application/pdf\"])\n    else:\n        raise","preventionTips":["Provide a default non-empty MIME type list","Validate config files guarantee at least one MIME type","Guard dynamically built lists before construction"],"tags":["python","validation","router","mime-type"],"backgroundTag":"empty-required-list","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}