{"record":{"id":"1d2105ca5daaa0b9","repo":"oraios/serena","slug":"failed-to-check-ocaml-lsp-server-installation-e","errorCode":null,"errorMessage":"Failed to check ocaml-lsp-server installation: {e.stderr}","messagePattern":"Failed to check ocaml-lsp-server installation: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/solidlsp/language_servers/ocaml_lsp_server.py","lineNumber":174,"sourceCode":"                cwd=repository_root_path,\n                **subprocess_kwargs(),\n            )\n            if \"ocaml-lsp-server\" not in result.stdout or \"# No matches found\" in result.stdout:\n                raise RuntimeError(\n                    \"ocaml-lsp-server is not installed.\\n\\n\"\n                    \"Please install it with:\\n\"\n                    \"  opam install ocaml-lsp-server\\n\\n\"\n                    \"Note: ocaml-lsp-server requires OCaml < 5.1 or >= 5.1.1 (OCaml 5.1.0 is not supported).\\n\"\n                    \"If you have OCaml 5.1.0, create a new opam switch with a compatible version:\\n\"\n                    \"  opam switch create <name> ocaml-base-compiler.4.14.2\\n\"\n                    \"  opam switch <name>\\n\"\n                    \"  eval $(opam env)\\n\"\n                    \"  opam install ocaml-lsp-server\\n\\n\"\n                    \"For more information: https://github.com/ocaml/ocaml-lsp\"\n                )\n            log.info(\"ocaml-lsp-server is installed\")\n        except subprocess.CalledProcessError as e:\n            raise RuntimeError(f\"Failed to check ocaml-lsp-server installation: {e.stderr}\")\n\n        # Find the executable path\n        try:\n            if platform.system() == \"Windows\":\n                result = subprocess_run(\n                    [\"opam\", \"exec\", \"--\", \"where\", \"ocamllsp\"],\n                    check=True,\n                    capture_output=True,\n                    text=True,\n                    cwd=repository_root_path,\n                    **subprocess_kwargs(),\n                )\n                executable_path = result.stdout.strip().split(\"\\n\")[0]\n            else:\n                result = subprocess_run(\n                    [\"opam\", \"exec\", \"--\", \"which\", \"ocamllsp\"],\n                    check=True,\n                    capture_output=True,","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/solidlsp/language_servers/ocaml_lsp_server.py#L156-L192","documentation":"Raised when the `opam list` command used to verify ocaml-lsp-server installation exits with a non-zero status (subprocess.CalledProcessError), and the library wraps it in a RuntimeError including opam's stderr. Unlike [290], this means the installation CHECK itself failed, not that the package is missing.","triggerScenarios":"Instantiating OcamlLSPServer when `opam list -- ... ocaml-lsp-server` returns non-zero — typically `opam: command not found`-style environment failures, a corrupted opam root, or opam errors about an uninitialized/invalid switch (opam itself may emit errors on stderr).","commonSituations":"opam not on PATH for the subprocess environment; opam root uninitialized (`opam init` never run); broken or corrupt switch (~/.opam damaged); restricted CI container with no opam config; HOME mismatch causing opam to fail.","solutions":["Run `opam list` manually in the repo root to see the actual opam error from stderr.","If opam is uninitialized, run `opam init` then `eval $(opam env)`.","Ensure the opam binary is on PATH for the process launching the server (env inheritance; in CI, source `~/.opam/opam-init/init.sh` or run `eval $(opam env)`).","Repair a broken switch with `opam switch repair` or recreate it with `opam switch create`."],"exampleFix":"// before (Python, env lacks opam)\nsubprocess.run([\"opam\", \"list\", ...])  # CalledProcessError: opam not found\n// after\nimport os, subprocess\nenv = os.environ.copy()\n# ensure opam env loaded, e.g. in shell: eval $(opam env)\nsubprocess.run([\"opam\", \"list\", ...], env=env, cwd=repository_root_path)","handlingStrategy":"try-catch","validationCode":"import shutil, subprocess\ndef opam_ok(repo_root):\n    if not shutil.which(\"opam\"):\n        return False\n    return subprocess.run([\"opam\", \"list\"], capture_output=True, cwd=repo_root).returncode == 0","typeGuard":null,"tryCatchPattern":"try:\n    server = OcamlLSPServer(repo_root)\nexcept RuntimeError as e:\n    if \"Failed to check ocaml-lsp-server installation\" in str(e):\n        run(\"opam init -y\") ; run(\"eval $(opam env)\")  # fix opam env, then retry\n    else:\n        raise","preventionTips":["Ensure opam is installed and on PATH before launching","Run `opam init` during environment provisioning","Verify `opam list` exits cleanly in a health check","Keep the opam root intact; avoid wiping ~/.opam without re-init"],"tags":["ocaml","opam","subprocess","environment-setup"],"backgroundTag":"opam-command-failed","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}