{"record":{"id":"40198d492de00d37","repo":"OpenBMB/ChatDev","slug":"functions-directory-does-not-exist-self-function","errorCode":null,"errorMessage":"Functions directory does not exist: {self.functions_dir}","messagePattern":"Functions directory does not exist: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"utils/function_manager.py","lineNumber":48,"sourceCode":"EDGE_FUNCTION_DIR = _resolve_dir(_DEFAULT_EDGE_FUNCTION_DIR, _EDGE_FUNCTION_ENV).resolve()\nEDGE_PROCESSOR_FUNCTION_DIR = _resolve_dir(_DEFAULT_EDGE_PROCESSOR_DIR, _EDGE_PROCESSOR_FUNCTION_ENV).resolve()\n\n\nclass FunctionManager:\n    \"\"\"Unified function manager for loading and managing functions across the project.\"\"\"\n\n    def __init__(self, functions_dir: str | Path = \"functions\") -> None:\n        self.functions_dir = Path(functions_dir)\n        self.functions: Dict[str, Callable] = {}\n        self._loaded = False\n\n    def load_functions(self) -> None:\n        \"\"\"Load all Python functions from functions directory.\"\"\"\n        if self._loaded:\n            return\n            \n        if not self.functions_dir.exists():\n            raise ValueError(f\"Functions directory does not exist: {self.functions_dir}\")\n\n        for file in self.functions_dir.rglob(\"*.py\"):\n            if file.name.startswith(\"_\") or file.name == \"__init__.py\":\n                continue\n            if \"__pycache__\" in file.parts:\n                continue\n                \n            module_name = self._build_module_name(file)\n            try:\n                # Import module dynamically\n                spec = importlib.util.spec_from_file_location(module_name, file)\n                if spec is None or spec.loader is None:\n                    continue\n                    \n                module = importlib.util.module_from_spec(spec)\n                spec.loader.exec_module(module)\n\n                current_file = file.resolve()","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/OpenBMB/ChatDev/blob/4fb2db0ea90375ce1059f44fe03ffbd191a7a169/utils/function_manager.py#L30-L66","documentation":"FunctionManager.load_functions raises ValueError when the configured functions directory does not exist on disk. Loading is lazy (first call to get_function/list_functions/call_function or refresh triggers it), so the error surfaces at first use, not at construction.","triggerScenarios":"Instantiating FunctionManager with a functions_dir path that is wrong or not yet created; relative path resolved from a different CWD; directory deleted or not shipped in a container/deployment.","commonSituations":"Default ./functions dir absent in a fresh clone or slim Docker image; path configured via env var pointing to a typo'd location; running the server from a different working directory.","solutions":["Create the directory (even empty) or fix the configured path","Pass an absolute path derived from a known base (e.g. Path(__file__).parent / 'functions')","If no custom functions are used, ensure the code skips FunctionManager or the dir is created at startup"],"exampleFix":"# before\nfm = FunctionManager(functions_dir=Path(\"functions\"))\n# after\nfdir = Path(\"functions\").resolve()\nfdir.mkdir(parents=True, exist_ok=True)\nfm = FunctionManager(functions_dir=fdir)","handlingStrategy":"validation","validationCode":"fdir = Path(functions_dir).resolve()\nif not fdir.is_dir():\n    fdir.mkdir(parents=True, exist_ok=True)  # or fail fast with clear message","typeGuard":"def has_functions_dir(d: str | Path) -> bool:\n    return Path(d).is_dir()","tryCatchPattern":"try:\n    fm.list_functions()\nexcept ValueError as e:\n    if 'does not exist' in str(e):\n        fix_functions_path_or_create()","preventionTips":["Configure absolute functions dir paths","Create the dir at app startup / in Dockerfile","Validate config paths in a boot health check"],"tags":["functions","config","directory-not-found"],"backgroundTag":"missing-config-directory","analyzedSha":"4fb2db0ea90375ce1059f44fe03ffbd191a7a169","analyzedAt":"2026-08-27T14:35:29.622Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}