{"record":{"id":"558375ea9ead521b","repo":"oraios/serena","slug":"mode-file-not-found-path-resolve","errorCode":null,"errorMessage":"Mode file not found: {path.resolve()}","messagePattern":"Mode file not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"src/serena/config/context_mode.py","lineNumber":137,"sourceCode":"        modes = [f.stem for f in Path(SERENAS_OWN_MODE_YAMLS_DIR).glob(\"*.yml\") if f.name != \"mode.template.yml\"]\n        if include_user_modes:\n            modes += cls.list_custom_mode_names()\n        return sorted(set(modes))\n\n    @classmethod\n    def list_custom_mode_names(cls) -> list[str]:\n        \"\"\"Names of all custom modes defined by the user.\"\"\"\n        return [f.stem for f in Path(SerenaPaths().user_modes_dir).glob(\"*.yml\")]\n\n    @classmethod\n    def load(cls, name_or_path: str | Path) -> Self:\n        # If it is a path or looks like a path, load from file\n        if isinstance(name_or_path, Path) or looks_like_yaml_path(str(name_or_path)):\n            path = Path(name_or_path)\n            if path.exists() and path.is_file():\n                return cls.from_yaml(name_or_path)\n            else:\n                raise FileNotFoundError(f\"Mode file not found: {path.resolve()}\")\n\n        # load from name\n        return cls.from_name(str(name_or_path))\n\n    def has_prompt(self) -> bool:\n        \"\"\"\n        :return: whether this mode defines a prompt\n        \"\"\"\n        return bool(self.prompt and self.prompt.strip())\n\n\n@dataclass(kw_only=True)\nclass SerenaAgentContext(ToolInclusionDefinition, ToStringMixin):\n    \"\"\"Represents a context where the agent is operating (an IDE, a chat, etc.), typically read off a YAML file.\n    An agent can only be in a single context at a time.\n    The contexts cannot be changed after the agent is running.\n    \"\"\"\n","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/serena/config/context_mode.py#L119-L155","documentation":"SerenaMode.load accepts either a registered mode name or a path to a mode YAML. If the argument looks like a YAML path (string ending like a yaml path or a Path object) but the file does not exist or is not a regular file, FileNotFoundError is raised with the resolved absolute path.","triggerScenarios":"Passing a Path or path-like string ('~/modes/custom.yml', './my-mode.yaml') to load() / mode configuration where the file is missing, deleted, renamed, or the '~' was not expanded (looks_like_yaml_path treats it as a path).","commonSituations":"Referencing a custom mode file that was moved or never created; using '~' in paths without expansion in a service context; relative path wrong because of different working directory (daemon/server cwd); typo in filename extension.","solutions":["Verify the file exists at the resolved path shown in the error and fix the path","Expand '~' and use absolute paths (Path.expanduser()) before passing","Check the working directory if using relative paths","Fall back to a registered mode name if the file was intentionally removed"],"exampleFix":"// before\nSerenaMode.load(Path(\"~/modes/my-mode.yml\"))\n// after\np = Path(\"~/modes/my-mode.yml\").expanduser()\nassert p.is_file(), p\nSerenaMode.load(p)","handlingStrategy":"validation","validationCode":"from pathlib import Path\np = Path(name_or_path).expanduser()\nif p.suffix in (\".yml\", \".yaml\") and not p.is_file():\n    raise FileNotFoundError(f\"Mode file missing: {p.resolve()}\")","typeGuard":"def is_existing_yaml_path(v) -> bool:\n    p = Path(v).expanduser()\n    return p.is_file() and p.suffix in (\".yml\", \".yaml\")","tryCatchPattern":"try:\n    mode = SerenaMode.load(mode_name_or_path)\nexcept FileNotFoundError as e:\n    logger.warning(\"Mode file missing: %s; using named mode\", e)\n    mode = SerenaMode.from_name(\"default\")","preventionTips":["Always expanduser() and resolve() paths before passing","Use absolute paths in services/containers with different cwd","Check the file exists after moving or renaming custom modes"],"tags":["configuration","file-not-found","path"],"backgroundTag":"config-file-not-found","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}