oraios/serena · error · FileNotFoundError

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

Error message

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

What it means

Serena's Context.load() accepts either a registered context name or a path to a YAML context file. This FileNotFoundError is raised when the argument looks like a YAML path (or is a Path object) but no file exists at that location. It means the loader determined you meant a file, not a name, and the file is missing.

Source

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

        if name in legacy_name_mapping:
            log.warning(
                f"Context name '{name}' is deprecated and has been renamed to '{legacy_name_mapping[name]}'. "
                f"Please update your configuration; refer to the configuration guide for more details: "
                "https://oraios.github.io/serena/02-usage/050_configuration.html#contexts"
            )
            name = legacy_name_mapping[name]
        context_path = cls.get_path(name)
        return cls.from_yaml(context_path)

    @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"Context file not found: {path.resolve()}")

        return cls.from_name(str(name_or_path))

    @classmethod
    def list_registered_context_names(cls, include_user_contexts: bool = True) -> list[str]:
        """Names of all registered contexts (from the corresponding YAML files in the serena repo)."""
        contexts = [f.stem for f in Path(SERENAS_OWN_CONTEXT_YAMLS_DIR).glob("*.yml")]
        if include_user_contexts:
            contexts += cls.list_custom_context_names()
        return sorted(set(contexts))

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

    @classmethod
    def load_default(cls) -> Self:

View on GitHub (pinned to 7fcbca7e62)

Solutions

  1. Verify the path exists and is a file: run ls/path.exists() and path.is_file() on the exact path.
  2. If you meant a registered context, pass just the name (e.g. 'desktop-app') without a .yml extension or path separators.
  3. If using a relative path, make it absolute or run the command from the intended working directory.
  4. Use Context.list_registered_context_names() to see available contexts, or copy a shipped YAML from the serena repo as a starting point.

Example fix

// before
ctx = Context.load("./cotexts/my_context.yml")  # typo, file not found
// after
ctx = Context.load("./contexts/my_context.yml")  # corrected path, or use a registered name:
# ctx = Context.load("my_context")
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

def validate_context_path(name_or_path):
    p = Path(name_or_path)
    if p.suffix in (".yml", ".yaml") or isinstance(name_or_path, Path):
        if not (p.exists() and p.is_file()):
            raise FileNotFoundError(f"Context file not found: {p.resolve()}")
    return p

Type guard

def is_existing_yaml_file(name_or_path) -> bool:
    p = Path(name_or_path)
    return p.exists() and p.is_file()

Try / catch

from serena.config.context import Context

try:
    ctx = Context.load(name_or_path)
except FileNotFoundError as e:
    print(f"{e}; available: {Context.list_registered_context_names()}")
    ctx = Context.load("default")

Prevention

When it happens

Trigger: Calling Context.load(Path('/path/to/context.yml')) or Context.load('./my_context.yaml') where the path does not exist or is a directory (path.is_file() fails). Note: if the path exists but is not a file, this error is also raised.

Common situations: Typos in the path, file deleted or moved after being referenced in a config, running from a different working directory with a relative path, passing a directory instead of a YAML file, or referencing a user context file that was never created.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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