{"record":{"id":"d4da22f5f587ca3d","repo":"iflytek/astron-agent","slug":"config-file-not-found-self-env-file-path","errorCode":null,"errorMessage":"Config file not found: {self.env_file_path}","messagePattern":"Config file not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"core/plugin/aitools/utils/config_utils.py","lineNumber":95,"sourceCode":"\n                    content = data.get(\"data\", {}).get(\"content\", \"\")\n                    config_dict = dotenv_values(stream=StringIO(content))\n\n                    return config_dict, content\n        except Exception as e:\n            log.exception(f\"Error downloading config from Polaris: {e}\")\n            raise\n\n\nclass EnvFileLoader:\n\n    def __init__(self, env_file_path: str) -> None:\n        self.env_file_path = env_file_path\n\n    def load_env_file(self) -> dict[str, Any]:\n        \"\"\"Load environment variables from a file specified by CONFIG_FILE_KEY.\"\"\"\n        if not os.path.exists(self.env_file_path):\n            raise FileNotFoundError(f\"Config file not found: {self.env_file_path}\")\n\n        config_dict = dotenv_values(self.env_file_path)\n\n        return dict(config_dict)\n\n\nclass ConfigWatcher:\n\n    def __init__(self) -> None:\n        self.enable_polaris: bool = False\n        self.enable_hot_reload: bool = False\n\n        self.env_loader: Optional[EnvFileLoader] = None\n        self.polaris_client: Optional[PolarisClient] = None\n        self.config_filter: Optional[ConfigFilter] = None\n        self.base_url: str = \"\"\n        self.username: str = \"\"\n        self.password: str = \"\"","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/plugin/aitools/utils/config_utils.py#L77-L113","documentation":"load_env_file loads key/value pairs from an env-style config file (via python-dotenv's dotenv_values) whose path was given to the constructor. Before reading, it checks os.path.exists and raises FileNotFoundError when the path does not point to an existing file, so the caller gets a clear, immediate failure instead of an empty config dict.","triggerScenarios":"Instantiating the config util with an env_file_path that does not exist on disk (typo, wrong relative path, file not mounted) and then calling load_env_file().","commonSituations":"Container deployments where the config file was not volume-mounted; CONFIG_FILE_KEY pointing to a stale or renamed file; running from a different working directory so relative paths resolve incorrectly; typo in the path string.","solutions":["Verify the file exists at the exact path with `ls -l <path>` and fix the path passed to the constructor / CONFIG_FILE_KEY","If running in Docker/K8s, mount the env file or bake it into the image at the expected path","Use an absolute path or resolve relative paths against a known base directory","Fail fast at startup with a friendly message telling the operator which path is missing"],"exampleFix":"// before\nloader = ConfigLoader('/etc/app/.env')\nconfig = loader.load_env_file()  # FileNotFoundError\n// after\nenv_path = os.environ.get('CONFIG_FILE_KEY', '/etc/app/.env')\nif not os.path.exists(env_path):\n    raise FileNotFoundError(f'Please provide the config file at {env_path}')\nloader = ConfigLoader(env_path)\nconfig = loader.load_env_file()","handlingStrategy":"validation","validationCode":"import os\npath = os.environ.get('CONFIG_FILE_KEY', default_path)\nif not os.path.isfile(path):\n    raise FileNotFoundError(f'Config file missing: {path}')","typeGuard":"def config_file_ok(path: str) -> bool:\n    return isinstance(path, str) and os.path.isfile(path)","tryCatchPattern":"try:\n    config = loader.load_env_file()\nexcept FileNotFoundError as e:\n    logger.error('Config file missing, check CONFIG_FILE_KEY: %s', e)\n    sys.exit(1)","preventionTips":["Mount/copy the env file in Docker/K8s at a fixed absolute path","Resolve relative paths against the project root, not the CWD","Fail at startup with a message naming the missing path","Add a smoke check in CI that the packaged config file exists"],"tags":["config","file-not-found","env"],"backgroundTag":"config-file-not-found","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}