{"record":{"id":"82dd967c25f8653a","repo":"assafelovic/gpt-researcher","slug":"invalid-type-for-path-expected-str-bytes-os-pat","errorCode":null,"errorMessage":"Invalid type for path. Expected str, bytes, os.PathLike, or list thereof.","messagePattern":"Invalid type for path\\. Expected str, bytes, os\\.PathLike, or list thereof\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"gpt_researcher/document/document.py","lineNumber":41,"sourceCode":"        tasks = []\n        if isinstance(self.path, list):\n            for file_path in self.path:\n                if os.path.isfile(file_path):  # Ensure it's a valid file\n                    filename = os.path.basename(file_path)\n                    file_name, file_extension_with_dot = os.path.splitext(filename)\n                    file_extension = file_extension_with_dot.strip(\".\").lower()\n                    tasks.append(self._load_document(file_path, file_extension))\n                    \n        elif isinstance(self.path, (str, bytes, os.PathLike)):\n            for root, dirs, files in os.walk(self.path):\n                for file in files:\n                    file_path = os.path.join(root, file)\n                    file_name, file_extension_with_dot = os.path.splitext(file)\n                    file_extension = file_extension_with_dot.strip(\".\").lower()\n                    tasks.append(self._load_document(file_path, file_extension))\n                    \n        else:\n            raise ValueError(\"Invalid type for path. Expected str, bytes, os.PathLike, or list thereof.\")\n\n        # for root, dirs, files in os.walk(self.path):\n        #     for file in files:\n        #         file_path = os.path.join(root, file)\n        #         file_name, file_extension_with_dot = os.path.splitext(file_path)\n        #         file_extension = file_extension_with_dot.strip(\".\")\n        #         tasks.append(self._load_document(file_path, file_extension))\n\n        docs = []\n        for pages in await asyncio.gather(*tasks):\n            for page in pages:\n                if page.page_content:\n                    docs.append({\n                        \"raw_content\": page.page_content,\n                        \"url\": os.path.basename(page.metadata['source'])\n                    })\n                    \n        if not docs:","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/assafelovic/gpt-researcher/blob/6f998577d547b1e54ec662dac63583aa11e3b84b/gpt_researcher/document/document.py#L23-L59","documentation":"DocumentLoader.load accepts str/bytes/os.PathLike (a single file/dir path) or a list of such paths; any other type (int, dict, None) reaches the final else and raises this ValueError.","triggerScenarios":"Calling DocumentLoader(None, ...).load() (path never set), passing a dict from another loader's output, or an int/None from upstream config like a missing DOC_PATH.","commonSituations":"Forgetting to pass the path kwarg; DOC_PATH env var unset so path is None; passing a tuple instead of list.","solutions":["Pass a str/Path or a list of them to DocumentLoader","Default/validate the path before constructing: Path(doc_path or './docs')","If multiple paths, use a list, not a tuple"],"exampleFix":"# before\nloader = DocumentLoader(None)\ndocs = loader.load()\n# after\nfrom pathlib import Path\nloader = DocumentLoader(str(Path(doc_path).expanduser()))\ndocs = loader.load()","handlingStrategy":"type-guard","validationCode":"import os\nfrom pathlib import Path\np = doc_path\nassert p is None or isinstance(p, (str, bytes, os.PathLike, list))\np = str(Path(p or \"./docs\").resolve())","typeGuard":"def is_loadable_path(p) -> bool:\n    if isinstance(p, (str, bytes, os.PathLike)):\n        return True\n    return isinstance(p, list) and all(isinstance(i, (str, bytes, os.PathLike)) for i in p)","tryCatchPattern":"try:\n    docs = loader.load()\nexcept ValueError as e:\n    if \"Invalid type for path\" in str(e):\n        docs = DocumentLoader(str(default_path)).load()\n    else: raise","preventionTips":["Always pass an explicit path","Default missing config paths before constructing loaders"],"tags":["python","document-loader","type-validation"],"backgroundTag":"invalid-argument-type","analyzedSha":"6f998577d547b1e54ec662dac63583aa11e3b84b","analyzedAt":"2026-08-28T17:50:07.383Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}