charmbracelet/gum · warning

could not parse version %s: %w

Error message

could not parse version %s: %w

What it means

The gum binary's own version string, taken from the kong context var 'versionNumber', could not be parsed as a semantic version. The constraint parsed fine, but the current version value is malformed. The parse error is wrapped with %w.

Source

Thrown at version/command.go:20

package version

import (
	"fmt"

	"github.com/Masterminds/semver/v3"
	"github.com/alecthomas/kong"
)

// Run check that a given version matches a semantic version constraint.
func (o Options) Run(ctx *kong.Context) error {
	c, err := semver.NewConstraint(o.Constraint)
	if err != nil {
		return fmt.Errorf("could not parse range %s: %w", o.Constraint, err)
	}
	current := ctx.Model.Vars()["versionNumber"]
	v, err := semver.NewVersion(current)
	if err != nil {
		return fmt.Errorf("could not parse version %s: %w", current, err)
	}
	if !c.Check(v) {
		return fmt.Errorf("gum version %q is not within given range %q", current, o.Constraint)
	}
	return nil
}

View on GitHub (pinned to 4d089f9550)

Solutions

  1. Install an official gum release where versionNumber is a valid semver
  2. Rebuild with proper ldflags, e.g. -X main.version=v0.14.0
  3. Check `gum --version` output to see what version string is being used
  4. If testing dev builds, pass a semver-compatible version at build time

Example fix

// before
go build -o gum ./...        # versionNumber empty → parse fails
// after
go build -ldflags "-X main.version=v0.14.1" -o gum .
Defensive patterns

Strategy: fallback

Validate before calling

ver=$(gum --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
[ -n "$ver" ] || echo 'warning: gum version not semver-parseable (dev build?)'

Try / catch

if ! gum version --check ">= 0.14.0" 2>/dev/null; then
  case "$?" in 0) ;; *) echo 'version check skipped (dev build)' ;; esac
fi

Prevention

When it happens

Trigger: `ctx.Model.Vars()["versionNumber"]` contains a value semver.NewVersion cannot parse — typically only when running an unreleased/dev build whose version var is empty or non-semantic, since normal builds inject a valid version.

Common situations: Building gum from source without version ldflags so versionNumber is empty or 'dev', altered binary metadata, or running a stripped/modified build.

Related errors


AI-assisted analysis of charmbracelet/gum@4d089f9550 (2026-08-31). Data as JSON: /api/errors/748a7f328b5d223a. Report an issue: GitHub.