{"record":{"id":"c5fdfbee9e374bc4","repo":"oraios/serena","slug":"failed-to-detect-ocaml-lsp-server-version-e-stde","errorCode":null,"errorMessage":"Failed to detect ocaml-lsp-server version: {e.stderr}\nPlease install ocaml-lsp-server:\n  opam install ocaml-lsp-server","messagePattern":"Failed to detect ocaml-lsp-server version: (.+?)\nPlease install ocaml-lsp-server:\n  opam install ocaml-lsp-server","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/solidlsp/language_servers/ocaml_lsp_server.py","lineNumber":137,"sourceCode":"                cwd=repository_root_path,\n                **subprocess_kwargs(),\n            )\n            version_str = result.stdout.strip()\n            version_match = re.search(r\"(\\d+)\\.(\\d+)\\.(\\d+)\", version_str)\n            if version_match:\n                major = int(version_match.group(1))\n                minor = int(version_match.group(2))\n                patch = int(version_match.group(3))\n                version_tuple = (major, minor, patch)\n                log.info(f\"ocaml-lsp-server version: {major}.{minor}.{patch}\")\n                return version_tuple\n            raise RuntimeError(\n                f\"Could not parse ocaml-lsp-server version from output: {version_str}\\n\"\n                \"Please ensure ocaml-lsp-server is properly installed:\\n\"\n                \"  opam list -i ocaml-lsp-server\"\n            )\n        except subprocess.CalledProcessError as e:\n            raise RuntimeError(\n                f\"Failed to detect ocaml-lsp-server version: {e.stderr}\\nPlease install ocaml-lsp-server:\\n  opam install ocaml-lsp-server\"\n            ) from e\n        except FileNotFoundError as e:\n            raise RuntimeError(\"opam not found. Please install opam:\\n  https://opam.ocaml.org/doc/Install.html\") from e\n\n    @staticmethod\n    def _ensure_ocaml_lsp_installed(repository_root_path: str) -> str:\n        \"\"\"\n        Ensure ocaml-lsp-server is installed and return the executable path.\n        Raises RuntimeError with helpful message if not installed.\n        \"\"\"\n        # Check if ocaml-lsp-server is installed\n        try:\n            result = subprocess_run(\n                [\"opam\", \"list\", \"-i\", \"ocaml-lsp-server\"],\n                check=False,\n                capture_output=True,\n                text=True,","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/solidlsp/language_servers/ocaml_lsp_server.py#L119-L155","documentation":"This RuntimeError is raised when the command used to detect the ocaml-lsp-server version exits with a non-zero status (subprocess.CalledProcessError), almost always because the ocaml-lsp-server opam package is not installed. The stderr is surfaced along with the fix command 'opam install ocaml-lsp-server'.","triggerScenarios":"Constructing the OCaml language server when the version-detection subprocess fails: ocaml-lsp-server missing from the active switch, opam query erroring, or a broken switch causing non-zero exit.","commonSituations":"New opam switch where only the compiler was installed and language-server packages were not; CI caching that skipped opam install steps; switch created after forgetting to install ocaml-lsp-server.","solutions":["Install the language server: opam install ocaml-lsp-server, then eval $(opam env).","If on a fresh switch, also ensure the base compiler and toolchain are installed (opam init / opam switch create ...).","Check stderr in the message for the real opam error and address it (network, repo not updated: opam update).","Verify installation: opam list -i ocaml-lsp-server."],"exampleFix":"// before (shell)\nopam switch create proj 5.1.1   # ocaml-lsp-server not installed\n// after\nopam switch create proj 5.1.1\nopam install -y ocaml-lsp-server\neval $(opam env)","handlingStrategy":"validation","validationCode":"import subprocess\n\ndef require_ocaml_lsp_installed() -> None:\n    r = subprocess.run(\n        [\"opam\", \"list\", \"--installed\", \"ocaml-lsp-server\"],\n        capture_output=True, text=True,\n    )\n    if r.returncode != 0 or not r.stdout.strip():\n        raise RuntimeError(\n            \"ocaml-lsp-server not installed in the active switch. \"\n            \"Run: opam install ocaml-lsp-server && eval $(opam env)\"\n        )","typeGuard":null,"tryCatchPattern":"try:\n    server = OcamlLanguageServer(**kwargs)\nexcept RuntimeError as e:\n    if \"Failed to detect ocaml-lsp-server version\" in str(e):\n        logger.error(\"Install the language server: opam install ocaml-lsp-server, then eval $(opam env). stderr: %s\", e)\n        raise\n    raise","preventionTips":["Add 'opam install -y ocaml-lsp-server' to setup scripts for every new switch, not just the first.","Run 'opam list -i ocaml-lsp-server' as a CI preflight before starting OCaml language services.","When caching opam roots in CI, include the language-server package in the cache key.","After creating any new opam switch, reinstall project dependencies including ocaml-lsp-server."],"tags":["ocaml","lsp","opam","missing-package","subprocess"],"backgroundTag":"missing-package","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}