oraios/serena · error · RuntimeError

MATLAB installation directory does not exist: {matlab_path}

Error message

MATLAB installation directory does not exist: {matlab_path}

What it means

get_matlab_path validates that the resolved MATLAB directory actually exists on disk. If MATLAB_PATH (or a caller-supplied path) points to a non-existent directory, RuntimeError is raised rather than silently launching the server against a bogus root.

Source

Thrown at src/solidlsp/language_servers/matlab_language_server.py:321

            raise RuntimeError(
                f"MATLAB installation not found. Set the {MATLAB_PATH_ENV_VAR} environment variable "
                "to your MATLAB installation directory (e.g., /Applications/MATLAB_R2024b.app on macOS, "
                "C:\\Program Files\\MATLAB\\R2024b on Windows, or /usr/local/MATLAB/R2024b on Linux)."
            )

        def get_matlab_path(self) -> str:
            """Get MATLAB path from settings or auto-detect."""
            if self._matlab_path is not None:
                return self._matlab_path

            matlab_path = self._custom_settings.get("matlab_path")

            if not matlab_path:
                matlab_path = self._find_matlab_installation()  # Raises RuntimeError if not found

            # Verify MATLAB path exists
            if not os.path.isdir(matlab_path):
                raise RuntimeError(f"MATLAB installation directory does not exist: {matlab_path}")

            log.info(f"Using MATLAB installation: {matlab_path}")

            self._matlab_path = matlab_path
            return matlab_path

        def create_launch_command(self) -> list[str]:
            # Verify node is installed
            node_path = shutil.which("node")
            if node_path is None:
                raise RuntimeError("Node.js is not installed or isn't in PATH. Please install Node.js and try again.")

            # Find existing extension or download if needed
            extension_path = self._find_matlab_extension()
            if extension_path is None:
                log.info("MATLAB extension not found on disk, attempting to download...")
                extension_path = self._download_and_install_matlab_extension()

View on GitHub (pinned to 7fcbca7e62)

Solutions

  1. Correct the MATLAB_PATH environment variable to an existing MATLAB directory (ls the path to verify)
  2. Update the path after a MATLAB version upgrade to the new install directory
  3. Verify with a directory check before starting the server: os.path.isdir(os.environ["MATLAB_PATH"])

Example fix

# before
export MATLAB_PATH=/usr/local/MATLAB/R2023a   # uninstalled
# after
export MATLAB_PATH=/usr/local/MATLAB/R2024b
Defensive patterns

Strategy: validation

Validate before calling

import os
matlab_path = os.environ.get("MATLAB_PATH", "")
if matlab_path and not os.path.isdir(matlab_path):
    raise RuntimeError(f"MATLAB_PATH points to a missing directory: {matlab_path}")

Type guard

def is_dir_path(p: str) -> bool:
    return bool(p) and os.path.isdir(p)

Try / catch

try:
    ls = SolidLSP("matlab")
except RuntimeError as e:
    if "does not exist" in str(e) and "MATLAB" in str(e):
        fix_matlab_path_to_existing_install(); ls = SolidLSP("matlab")
    else:
        raise

Prevention

When it happens

Trigger: Setting MATLAB_PATH (or passing matlab_path to get_matlab_path) to a path that is not a directory — a typo, a stale path after uninstalling/upgrading MATLAB (e.g. R2024b removed, now R2025a), or a path with wrong casing/drive letter on Windows.

Common situations: Upgrading MATLAB versions leaves an old env var pointing at the deleted install; container image rebakes with a different MATLAB path; trailing mistakes like pointing at a file instead of a directory.

Related errors


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