oraios/serena · error · RuntimeError
Could not parse OCaml version from output: {result.stdout.st
Error message
Could not parse OCaml version from output: {result.stdout.strip()}
Please ensure OCaml is properly installed: opam exec -- ocaml -version What it means
This RuntimeError is raised when 'opam exec -- ocaml -version' succeeds but its output does not match the expected OCaml version pattern, so no version triple could be parsed. _detect_ocaml_version validates the toolchain at startup and cannot proceed without knowing the version. The raw unparsed stdout is included to aid diagnosis.
Source
Thrown at src/solidlsp/language_servers/ocaml_lsp_server.py:89
)
version_match = re.search(r"(\d+)\.(\d+)\.(\d+)", result.stdout)
if version_match:
major = int(version_match.group(1))
minor = int(version_match.group(2))
patch = int(version_match.group(3))
version_tuple = (major, minor, patch)
version_str = f"{major}.{minor}.{patch}"
log.info(f"OCaml version: {version_str}")
if version_tuple == (5, 1, 0):
raise RuntimeError(
f"OCaml {version_str} is incompatible with ocaml-lsp-server.\n"
"Please use OCaml < 5.1 or >= 5.1.1.\n"
"Consider creating a new opam switch:\n"
" opam switch create <name> ocaml-base-compiler.4.14.2"
)
return version_tuple
raise RuntimeError(
f"Could not parse OCaml version from output: {result.stdout.strip()}\n"
"Please ensure OCaml is properly installed: opam exec -- ocaml -version"
)
except subprocess.CalledProcessError as e:
raise RuntimeError(
f"Failed to detect OCaml version: {e.stderr}\n"
"Please ensure OCaml is installed and opam is configured:\n"
" opam switch show\n"
" opam exec -- ocaml -version"
) from e
except FileNotFoundError as e:
raise RuntimeError(
"OCaml not found. Please install OCaml via opam:\n"
" opam switch create <name> ocaml-base-compiler.4.14.2\n"
" eval $(opam env)"
) from e
@staticmethodView on GitHub (pinned to 7fcbca7e62)
Solutions
- Run 'opam exec -- ocaml -version' manually and check that output contains a parseable version like 'The OCaml toplevel, version 5.1.1'.
- Remove or fix any ocaml shim/wrapper script or PATH entry shadowing the real compiler.
- Ensure the correct opam switch is active (eval $(opam env)) so the expected ocaml binary runs.
- Suppress or redirect any extra stdout noise (warnings) coming from shell init or wrappers.
Example fix
// before: ~/bin/ocaml wrapper prints banner text then execs real ocaml #!/bin/sh echo "custom ocaml wrapper v2" exec /usr/bin/ocaml "$@" // after #!/bin/sh exec /home/user/.opam/default/bin/ocaml "$@"
Defensive patterns
Strategy: validation
Validate before calling
import re, subprocess
def ocaml_version_parses() -> tuple:
r = subprocess.run(
["opam", "exec", "--", "ocaml", "-version"],
capture_output=True, text=True, check=True,
)
m = re.search(r"version\s+(\d+)\.(\d+)\.(\d+)", r.stdout)
if not m:
raise RuntimeError(
f"Unparseable 'ocaml -version' output: {r.stdout!r}. "
"Check for ocaml shims on PATH or extra stdout noise."
)
return tuple(map(int, m.groups())) Try / catch
try:
server = OcamlLanguageServer(**kwargs)
except RuntimeError as e:
if "Could not parse OCaml version" in str(e):
logger.error("Fix the ocaml toolchain so 'opam exec -- ocaml -version' prints a standard version line. Raw output shown in the error.")
raise
raise Prevention
- Avoid wrapper/shim scripts named 'ocaml' that add stdout output; keep the real binary first on PATH.
- Test the raw output of 'opam exec -- ocaml -version' after any toolchain change.
- Silence shell-init warnings that could pollute subprocess stdout.
- Use official compiler packages from opam rather than custom-patched builds.
When it happens
Trigger: Constructing the OCaml language server when the 'ocaml -version' output is nonstandard: a wrapper/shim printing extra text, a customized ocaml build whose banner differs (e.g. missing 'The OCaml' version line format), locale/alias interference, or output from an unexpected binary named ocaml earlier on PATH.
Common situations: Custom opam wraps or scripts shadowing ocaml; minimal/embedded OCaml builds with altered version strings; environment where 'opam exec -- ocaml -version' emits warnings to stdout that break the regex.
Related errors
- Could not parse ocaml-lsp-server version from output: {versi
- OPAM is not installed or not in PATH. Please install OPAM fr
- OCaml 5.1.0 is incompatible with ocaml-lsp-server. Please us
- Failed to detect OCaml version: {e.stderr} Please ensure OCa
- OCaml not found. Please install OCaml via opam: opam switc
AI-assisted analysis of oraios/serena@7fcbca7e62 (2026-08-29).
Data as JSON: /api/errors/845614039b4a1c47.
Report an issue: GitHub.