{"record":{"id":"1d197ef36a30147d","repo":"oraios/serena","slug":"ocaml-5-1-0-is-incompatible-with-ocaml-lsp-server","errorCode":null,"errorMessage":"OCaml 5.1.0 is incompatible with ocaml-lsp-server.\nPlease use OCaml < 5.1 or >= 5.1.1.\nConsider creating a new opam switch:\n  opam switch create <name> ocaml-base-compiler.4.14.2","messagePattern":"OCaml 5\\.1\\.0 is incompatible with ocaml-lsp-server\\.\nPlease use OCaml < 5\\.1 or >= 5\\.1\\.1\\.\nConsider creating a new opam switch:\n  opam switch create <name> ocaml-base-compiler\\.4\\.14\\.2","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/solidlsp/language_servers/ocaml_lsp_server.py","lineNumber":82,"sourceCode":"            result = subprocess_run(\n                [\"opam\", \"exec\", \"--\", \"ocaml\", \"-version\"],\n                check=True,\n                capture_output=True,\n                text=True,\n                cwd=repository_root_path,\n                **subprocess_kwargs(),\n            )\n            version_match = re.search(r\"(\\d+)\\.(\\d+)\\.(\\d+)\", result.stdout)\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                version_str = f\"{major}.{minor}.{patch}\"\n                log.info(f\"OCaml version: {version_str}\")\n\n                if version_tuple == (5, 1, 0):\n                    raise RuntimeError(\n                        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:","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/solidlsp/language_servers/ocaml_lsp_server.py#L64-L100","documentation":"This RuntimeError is raised because ocaml-lsp-server is known to be incompatible with exactly OCaml 5.1.0. _detect_ocaml_version runs 'opam exec -- ocaml -version', parses the triple, and deliberately rejects the (5,1,0) tuple at startup. The error advises using OCaml < 5.1 or >= 5.1.1 via a new opam switch.","triggerScenarios":"Constructing the OCaml language server while the active opam switch uses OCaml 5.1.0; _detect_ocaml_version parses version 5.1.0 from 'ocaml -version' output and hits the explicit version_tuple == (5, 1, 0) check.","commonSituations":"A project pinned to OCaml 5.1.0 in its opam switch; a newly created switch defaulting to 5.1.0 before the 5.1.1 patch; team lockfiles that selected the buggy release.","solutions":["Create a new opam switch with a compatible compiler: opam switch create <name> ocaml-base-compiler.4.14.2 (or >= 5.1.1).","Run eval $(opam env) to activate the new switch, then retry.","Alternatively upgrade the existing switch: opam switch set <switch-with-5.1.1+> or reinstall packages on 5.1.1.","Verify with 'opam exec -- ocaml -version' that the active compiler is not 5.1.0."],"exampleFix":"// before (shell)\nopam switch list  # shows 5.1.0 active\n// after\nopam switch create ocaml-5-1-1 ocaml-base-compiler.5.1.1\neval $(opam env)","handlingStrategy":"validation","validationCode":"import re, subprocess\n\ndef require_compatible_ocaml() -> tuple:\n    out = subprocess.run(\n        [\"opam\", \"exec\", \"--\", \"ocaml\", \"-version\"],\n        capture_output=True, text=True, check=True,\n    ).stdout\n    m = re.search(r\"(\\d+)\\.(\\d+)\\.(\\d+)\", out)\n    if not m:\n        raise RuntimeError(f\"Cannot parse OCaml version from: {out!r}\")\n    v = tuple(map(int, m.groups()))\n    if v == (5, 1, 0):\n        raise RuntimeError(\n            \"OCaml 5.1.0 is incompatible with ocaml-lsp-server; \"\n            \"use < 5.1 or >= 5.1.1 (e.g. opam switch create <name> ocaml-base-compiler.5.1.1)\"\n        )\n    return v","typeGuard":null,"tryCatchPattern":"try:\n    server = OcamlLanguageServer(**kwargs)\nexcept RuntimeError as e:\n    if \"5.1.0\" in str(e) and \"incompatible\" in str(e):\n        raise SystemExit(\n            \"Pin the project switch to a compatible compiler: \"\n            \"opam switch create proj ocaml-base-compiler.5.1.1 && eval $(opam env)\"\n        ) from e\n    raise","preventionTips":["Pin the switch compiler in your project (e.g. *.opam.locked / CI setup-opam step) and avoid 5.1.0.","Check 'opam exec -- ocaml -version' as a preflight in CI before starting the server.","Keep switch definitions in version control so all devs get a compatible compiler.","If forced onto 5.1.0 by a dependency, upgrade to >= 5.1.1 which contains the fix."],"tags":["ocaml","version-incompatibility","opam","lsp"],"backgroundTag":"version-incompatible","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}