{"record":{"id":"aadb23c41486bf79","repo":"deepset-ai/haystack","slug":"file-not-found-source","errorCode":null,"errorMessage":"File not found: {source}","messagePattern":"File not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"haystack/components/routers/file_type_router.py","lineNumber":166,"sourceCode":"            If it's a list, its length must match the number of sources, as they are zipped together.\n\n        :returns: A dictionary where the keys are MIME types and the values are lists of data sources.\n                  Two extra keys may be returned: `\"unclassified\"` when a source's MIME type doesn't match any pattern\n                   and `\"failed\"` when a source cannot be processed (for example, a file path that doesn't exist).\n        :raises TypeError: If a source is not a Path, str, or ByteStream.\n        \"\"\"\n\n        mime_types: defaultdict[str, list[Path | ByteStream]] = defaultdict(list)\n        meta_list = normalize_metadata(meta=meta, sources_count=len(sources))\n\n        for source, meta_dict in zip(sources, meta_list, strict=True):\n            if isinstance(source, str):\n                source = Path(source)\n\n            if isinstance(source, Path):\n                if not source.exists():\n                    if self._raise_on_failure:\n                        raise FileNotFoundError(f\"File not found: {source}\")\n                    logger.warning(\"File not found: {source}. Skipping it.\", source=source)\n                    mime_types[\"failed\"].append(source)\n                    continue\n\n                mime_type = _guess_mime_type(source)\n\n            elif isinstance(source, ByteStream):\n                mime_type = source.mime_type\n            else:\n                raise TypeError(f\"Unsupported data source type: {type(source).__name__}\")\n\n            # If we have metadata, we convert the source to ByteStream and add the metadata\n            if meta_dict:\n                try:\n                    source = get_bytestream_from_source(source)\n                except Exception as e:\n                    if self._raise_on_failure:\n                        raise e","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/routers/file_type_router.py#L148-L184","documentation":"FileTypeRouter.run raises FileNotFoundError for a Path/str source that does not exist on disk when raise_on_failure=True was set at construction. Otherwise it only logs a warning and routes the file to the 'failed' output.","triggerScenarios":"run(sources=[Path('/missing/file.pdf')]) on a router built with raise_on_failure=True.","commonSituations":"Files moved/deleted between pipeline steps; wrong mount paths in containers; relative paths resolved from an unexpected working directory.","solutions":["Check the path exists with Path(source).exists() before calling run","Construct the router with raise_on_failure=False to skip missing files with a warning","Fix the path (absolute path or correct working directory / volume mount)"],"exampleFix":"# before\nrouter = FileTypeRouter(mime_types=[\"application/pdf\"], raise_on_failure=True)\nrouter.run(sources=[\"missing.pdf\"])\n# after\nfrom pathlib import Path\nexisting = [s for s in [\"missing.pdf\"] if Path(s).exists()]\nrouter.run(sources=existing)  # or set raise_on_failure=False\n","handlingStrategy":"type-guard","validationCode":"from pathlib import Path\nmissing = [s for s in sources if isinstance(s, (str, Path)) and not Path(s).exists()]","typeGuard":"def file_exists(source) -> bool:\n    from pathlib import Path\n    return isinstance(source, (str, Path)) and Path(source).exists()","tryCatchPattern":"try:\n    result = router.run(sources=sources)\nexcept FileNotFoundError as e:\n    logging.warning(\"Skipping missing file: %s\", e)\n    sources = [s for s in sources if file_exists(s)]\n    result = router.run(sources=sources)","preventionTips":["Construct the router with raise_on_failure=False to skip missing files gracefully","Resolve and normalize paths (absolute) before passing them","Verify volume mounts / working directories in containerized runs","Filter sources with Path.exists() before run"],"tags":["python","filesystem","file-not-found","router"],"backgroundTag":"file-not-found","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}