{"record":{"id":"845614039b4a1c47","repo":"oraios/serena","slug":"could-not-parse-ocaml-version-from-output-result","errorCode":null,"errorMessage":"Could not parse OCaml version from output: {result.stdout.strip()}\nPlease ensure OCaml is properly installed: opam exec -- ocaml -version","messagePattern":"Could not parse OCaml version from output: (.+?)\nPlease ensure OCaml is properly installed: opam exec -- ocaml -version","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/solidlsp/language_servers/ocaml_lsp_server.py","lineNumber":89,"sourceCode":"            )\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:\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","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/solidlsp/language_servers/ocaml_lsp_server.py#L71-L107","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: ~/bin/ocaml wrapper prints banner text then execs real ocaml\n#!/bin/sh\necho \"custom ocaml wrapper v2\"\nexec /usr/bin/ocaml \"$@\"\n// after\n#!/bin/sh\nexec /home/user/.opam/default/bin/ocaml \"$@\"","handlingStrategy":"validation","validationCode":"import re, subprocess\n\ndef ocaml_version_parses() -> tuple:\n    r = subprocess.run(\n        [\"opam\", \"exec\", \"--\", \"ocaml\", \"-version\"],\n        capture_output=True, text=True, check=True,\n    )\n    m = re.search(r\"version\\s+(\\d+)\\.(\\d+)\\.(\\d+)\", r.stdout)\n    if not m:\n        raise RuntimeError(\n            f\"Unparseable 'ocaml -version' output: {r.stdout!r}. \"\n            \"Check for ocaml shims on PATH or extra stdout noise.\"\n        )\n    return tuple(map(int, m.groups()))","typeGuard":null,"tryCatchPattern":"try:\n    server = OcamlLanguageServer(**kwargs)\nexcept RuntimeError as e:\n    if \"Could not parse OCaml version\" in str(e):\n        logger.error(\"Fix the ocaml toolchain so 'opam exec -- ocaml -version' prints a standard version line. Raw output shown in the error.\")\n        raise\n    raise","preventionTips":["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."],"tags":["ocaml","opam","version-parse","output-parsing"],"backgroundTag":"version-parse-failed","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}