{"record":{"id":"05b47017a72c3975","repo":"oraios/serena","slug":"ocaml-not-found-please-install-ocaml-via-opam","errorCode":null,"errorMessage":"OCaml not found. Please install OCaml via opam:\n  opam switch create <name> ocaml-base-compiler.4.14.2\n  eval $(opam env)","messagePattern":"OCaml not found\\. Please install OCaml via opam:\n  opam switch create <name> ocaml-base-compiler\\.4\\.14\\.2\n  eval \\$\\(opam env\\)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/solidlsp/language_servers/ocaml_lsp_server.py","lineNumber":101,"sourceCode":"                        f\"OCaml {version_str} is incompatible with ocaml-lsp-server.\\n\"\n                        \"Please use OCaml < 5.1 or >= 5.1.1.\\n\"\n                        \"Consider creating a new opam switch:\\n\"\n                        \"  opam switch create <name> ocaml-base-compiler.4.14.2\"\n                    )\n                return version_tuple\n            raise RuntimeError(\n                f\"Could not parse OCaml version from output: {result.stdout.strip()}\\n\"\n                \"Please ensure OCaml is properly installed: opam exec -- ocaml -version\"\n            )\n        except subprocess.CalledProcessError as e:\n            raise RuntimeError(\n                f\"Failed to detect OCaml version: {e.stderr}\\n\"\n                \"Please ensure OCaml is installed and opam is configured:\\n\"\n                \"  opam switch show\\n\"\n                \"  opam exec -- ocaml -version\"\n            ) from e\n        except FileNotFoundError as e:\n            raise RuntimeError(\n                \"OCaml not found. Please install OCaml via opam:\\n\"\n                \"  opam switch create <name> ocaml-base-compiler.4.14.2\\n\"\n                \"  eval $(opam env)\"\n            ) from e\n\n    @staticmethod\n    def _detect_lsp_version(repository_root_path: str) -> tuple[int, int, int]:\n        \"\"\"\n        Detect and return the ocaml-lsp-server version as a tuple (major, minor, patch).\n        Raises RuntimeError if version cannot be determined.\n        \"\"\"\n        try:\n            result = subprocess_run(\n                [\"opam\", \"list\", \"-i\", \"ocaml-lsp-server\", \"--columns=version\", \"--short\"],\n                check=True,\n                capture_output=True,\n                text=True,\n                cwd=repository_root_path,","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/solidlsp/language_servers/ocaml_lsp_server.py#L83-L119","documentation":"This RuntimeError is raised when the OCaml compiler binary itself cannot be found: 'opam exec -- ocaml -version' raised FileNotFoundError. Unlike error 282 (opam missing), here opam exists but cannot locate or execute the ocaml binary. The message suggests creating a compiler via opam switch.","triggerScenarios":"Constructing the OCaml language server when opam is on PATH but no switch contains the ocaml compiler, or the switch's bin directory is missing/corrupted, causing FileNotFoundError from the subprocess call in _detect_ocaml_version.","commonSituations":"Fresh opam install with no switches created; switch deleted or its ~/.opam/<switch> directory removed while still selected; partially failed switch install leaving ocaml absent; PATH stripped so opam's env can't resolve ocaml.","solutions":["Create/repair a compiler switch: opam switch create <name> ocaml-base-compiler.4.14.2 then eval $(opam env).","Check 'opam switch list' and select an existing valid switch: opam switch set <name>.","If the switch directory is corrupted, remove it (opam switch remove <name>) and recreate it.","Confirm with 'opam exec -- ocaml -version' that ocaml now runs."],"exampleFix":"// before (shell)\nopam switch list  # empty or broken\n// after\nopam switch create myproj ocaml-base-compiler.4.14.2\neval $(opam env)\nopam install -y ocaml-lsp-server","handlingStrategy":"validation","validationCode":"import shutil, subprocess\n\ndef require_ocaml_compiler() -> None:\n    if shutil.which(\"opam\") is None:\n        raise RuntimeError(\"opam missing; install from https://opam.ocaml.org/doc/Install.html\")\n    r = subprocess.run(\n        [\"opam\", \"exec\", \"--\", \"ocaml\", \"-version\"], capture_output=True, text=True,\n    )\n    if r.returncode != 0 or \"version\" not in r.stdout:\n        raise RuntimeError(\n            \"ocaml compiler not available via opam. Create a switch: \"\n            \"opam switch create <name> ocaml-base-compiler.4.14.2 && eval $(opam env)\"\n        )","typeGuard":null,"tryCatchPattern":"try:\n    server = OcamlLanguageServer(**kwargs)\nexcept RuntimeError as e:\n    if \"OCaml not found\" in str(e):\n        logger.error(\"Create/repair an opam switch with a compiler, then eval $(opam env): %s\", e)\n        raise\n    raise","preventionTips":["Verify 'opam switch list' shows a switch with an installed compiler before starting dev work.","After recreating or switching environments, always 'eval $(opam env)' before launching servers.","Avoid deleting switch directories manually; use 'opam switch remove'.","In CI, cache the full opam root including the compiler, not just opam itself."],"tags":["ocaml","opam","missing-binary","switch"],"backgroundTag":"missing-binary","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}