{"record":{"id":"69f2e0cd4cf977ba","repo":"JanDeDobbeleer/oh-my-posh","slug":"cannot-parse-version-string","errorCode":null,"errorMessage":"cannot parse version string","messagePattern":"cannot parse version string","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/segments/language.go","lineNumber":91,"sourceCode":"\texecutable         string\n\tregex              string\n\tversionURLTemplate string\n\targs               []string\n\tenvs               []string\n\t// versionCacheable opts this command's raw output into the keyed device\n\t// cache (see Language.versionCacheKey): set it only when the output is a\n\t// pure function of the resolved executable - its path, mtime and size -\n\t// and the exact args, with no cwd file, environment variable, or project\n\t// config able to change what that same binary prints. A getVersion-backed\n\t// command never reaches the cache regardless of this flag, since the\n\t// cache sits in the executable-invocation branch of runCommand.\n\tversionCacheable bool\n}\n\nfunc (c *cmd) parse(versionInfo string) (*Version, error) {\n\tvalues := regex.FindNamedRegexMatch(c.regex, versionInfo)\n\tif len(values) == 0 {\n\t\treturn nil, errors.New(\"cannot parse version string\")\n\t}\n\n\tversion := &Version{\n\t\tFull:          values[\"version\"],\n\t\tMajor:         values[\"major\"],\n\t\tMinor:         values[\"minor\"],\n\t\tPatch:         values[\"patch\"],\n\t\tPrerelease:    values[\"prerelease\"],\n\t\tBuildMetadata: values[\"buildmetadata\"],\n\t}\n\treturn version, nil\n}\n\n// languageVersionFields lists what the version fetch populates: the\n// embedded Version struct's promoted fields (plus the embedded field name\n// itself), the fetch-path errors, and the version-file mismatch state.\n// setVersion and the mismatch check only run when one of these is\n// referenced; see fetchUnitFailOpen for the fail-open polarity.","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/segments/language.go#L73-L109","documentation":"The language segment runs a version command (e.g. `node --version`) and parses its output with the command's regex. cmd.parse() returns this error when the regex finds no named matches in the version string, meaning the tool's output format doesn't match what the segment expects.","triggerScenarios":"A version command's output doesn't contain the expected pattern: unusual version formats (e.g. 'v' prefixes, extra text), non-version output (warnings, banners, deprecation notices printed before the version), or a custom `version_regex` in the theme that doesn't match.","commonSituations":"Tool updated and changed its version output format; user supplied a custom version_regex with a typo or missing named groups; command prints locale-specific or noisy output; output captured includes a startup banner.","solutions":["Run the version command manually (e.g. `node --version`) and compare its exact output against the segment's version_regex.","Set a custom `version_regex` in the theme that matches your tool's output and includes the required named groups (version/major/minor).","Remove env vars or shell rc output that injects banners/warnings into the command output.","Upgrade or downgrade the language tool to a version whose output matches the default regex."],"exampleFix":"// before (theme)\n\"version_regex\": \"(?P<version>[0-9.]+)\"\n// after — tolerate a leading v\n\"version_regex\": \"v?(?P<version>(?P<major>[0-9]+)\\.(?P<minor>[0-9]+)[0-9.]*)\"","handlingStrategy":"validation","validationCode":"// verify your regex matches real output before adding it to the theme\nnode --version | grep -P 'v?(?P<version>[0-9]+\\.[0-9]+)'\n","typeGuard":null,"tryCatchPattern":"// segment logs and continues to the next display command; wrap custom probes:\nout, err := runVersionCmd();\nif err == nil && regexMatches(versionRegex, out) { /* safe to parse */ }","preventionTips":["Run the version command manually and test your version_regex against its exact output.","Include all required named groups (version, major, minor) in custom regexes.","Suppress rc-file banners/warnings that pollute command stdout.","Re-check regexes after upgrading the language tool."],"tags":["regex","version-parsing","language-segment"],"backgroundTag":"version-parse-failed","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}