oraios/serena · error · FileNotFoundError

Mode file not found: {path.resolve()}

Error message

Mode file not found: {path.resolve()}

What it means

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.

Source

Thrown at src/serena/config/context_mode.py:137

        modes = [f.stem for f in Path(SERENAS_OWN_MODE_YAMLS_DIR).glob("*.yml") if f.name != "mode.template.yml"]
        if include_user_modes:
            modes += cls.list_custom_mode_names()
        return sorted(set(modes))

    @classmethod
    def list_custom_mode_names(cls) -> list[str]:
        """Names of all custom modes defined by the user."""
        return [f.stem for f in Path(SerenaPaths().user_modes_dir).glob("*.yml")]

    @classmethod
    def load(cls, name_or_path: str | Path) -> Self:
        # If it is a path or looks like a path, load from file
        if isinstance(name_or_path, Path) or looks_like_yaml_path(str(name_or_path)):
            path = Path(name_or_path)
            if path.exists() and path.is_file():
                return cls.from_yaml(name_or_path)
            else:
                raise FileNotFoundError(f"Mode file not found: {path.resolve()}")

        # load from name
        return cls.from_name(str(name_or_path))

    def has_prompt(self) -> bool:
        """
        :return: whether this mode defines a prompt
        """
        return bool(self.prompt and self.prompt.strip())


@dataclass(kw_only=True)
class SerenaAgentContext(ToolInclusionDefinition, ToStringMixin):
    """Represents a context where the agent is operating (an IDE, a chat, etc.), typically read off a YAML file.
    An agent can only be in a single context at a time.
    The contexts cannot be changed after the agent is running.
    """

View on GitHub (pinned to 7fcbca7e62)

Solutions

  1. Verify the file exists at the resolved path shown in the error and fix the path
  2. Expand '~' and use absolute paths (Path.expanduser()) before passing
  3. Check the working directory if using relative paths
  4. Fall back to a registered mode name if the file was intentionally removed

Example fix

// before
SerenaMode.load(Path("~/modes/my-mode.yml"))
// after
p = Path("~/modes/my-mode.yml").expanduser()
assert p.is_file(), p
SerenaMode.load(p)
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path
p = Path(name_or_path).expanduser()
if p.suffix in (".yml", ".yaml") and not p.is_file():
    raise FileNotFoundError(f"Mode file missing: {p.resolve()}")

Type guard

def is_existing_yaml_path(v) -> bool:
    p = Path(v).expanduser()
    return p.is_file() and p.suffix in (".yml", ".yaml")

Try / catch

try:
    mode = SerenaMode.load(mode_name_or_path)
except FileNotFoundError as e:
    logger.warning("Mode file missing: %s; using named mode", e)
    mode = SerenaMode.from_name("default")

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of oraios/serena@7fcbca7e62 (2026-08-29). Data as JSON: /api/errors/558375ea9ead521b. Report an issue: GitHub.