JanDeDobbeleer/oh-my-posh · error

cannot parse version string

Error message

cannot parse version string

What it means

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.

Source

Thrown at src/segments/language.go:91

	executable         string
	regex              string
	versionURLTemplate string
	args               []string
	envs               []string
	// versionCacheable opts this command's raw output into the keyed device
	// cache (see Language.versionCacheKey): set it only when the output is a
	// pure function of the resolved executable - its path, mtime and size -
	// and the exact args, with no cwd file, environment variable, or project
	// config able to change what that same binary prints. A getVersion-backed
	// command never reaches the cache regardless of this flag, since the
	// cache sits in the executable-invocation branch of runCommand.
	versionCacheable bool
}

func (c *cmd) parse(versionInfo string) (*Version, error) {
	values := regex.FindNamedRegexMatch(c.regex, versionInfo)
	if len(values) == 0 {
		return nil, errors.New("cannot parse version string")
	}

	version := &Version{
		Full:          values["version"],
		Major:         values["major"],
		Minor:         values["minor"],
		Patch:         values["patch"],
		Prerelease:    values["prerelease"],
		BuildMetadata: values["buildmetadata"],
	}
	return version, nil
}

// languageVersionFields lists what the version fetch populates: the
// embedded Version struct's promoted fields (plus the embedded field name
// itself), the fetch-path errors, and the version-file mismatch state.
// setVersion and the mismatch check only run when one of these is
// referenced; see fetchUnitFailOpen for the fail-open polarity.

View on GitHub (pinned to 0976794618)

Solutions

  1. Run the version command manually (e.g. `node --version`) and compare its exact output against the segment's version_regex.
  2. Set a custom `version_regex` in the theme that matches your tool's output and includes the required named groups (version/major/minor).
  3. Remove env vars or shell rc output that injects banners/warnings into the command output.
  4. Upgrade or downgrade the language tool to a version whose output matches the default regex.

Example fix

// before (theme)
"version_regex": "(?P<version>[0-9.]+)"
// after — tolerate a leading v
"version_regex": "v?(?P<version>(?P<major>[0-9]+)\.(?P<minor>[0-9]+)[0-9.]*)"
Defensive patterns

Strategy: validation

Validate before calling

// verify your regex matches real output before adding it to the theme
node --version | grep -P 'v?(?P<version>[0-9]+\.[0-9]+)'

Try / catch

// segment logs and continues to the next display command; wrap custom probes:
out, err := runVersionCmd();
if err == nil && regexMatches(versionRegex, out) { /* safe to parse */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31). Data as JSON: /api/errors/69f2e0cd4cf977ba. Report an issue: GitHub.