derailed/k9s · error

could not convert revision to a number: %w

Error message

could not convert revision to a number: %w

What it means

Thrown by HelmHistory.Rollback when strconv.Atoi fails on the revision argument. The DAO maps the string revision (as printed by helm history) onto action.Rollback.Version, which is an int, so any non-decimal value cannot be converted. The %w wraps the strconv error, which names the offending input.

Source

Thrown at internal/dao/helm_history.go:147

	if allValues {
		content = resp.Release.Chart.Values
	} else {
		content = resp.Release.Config
	}

	return data.WriteYAML(content)
}

func (h *HelmHistory) Rollback(_ context.Context, path, rev string) error {
	ns, n := client.Namespaced(path)
	cfg, err := ensureHelmConfig(h.Client().Config().Flags(), ns)
	if err != nil {
		return err
	}

	ver, err := strconv.Atoi(rev)
	if err != nil {
		return fmt.Errorf("could not convert revision to a number: %w", err)
	}
	clt := action.NewRollback(cfg)
	clt.Version = ver

	return clt.Run(n)
}

// Delete uninstall a Helm.
func (h *HelmHistory) Delete(_ context.Context, path string, _ *metav1.DeletionPropagation, _ Grace) error {
	ns, n := client.Namespaced(path)
	cfg, err := ensureHelmConfig(h.Client().Config().Flags(), ns)
	if err != nil {
		return err
	}

	res, err := action.NewUninstall(cfg).Run(n)
	if err != nil {
		return err

View on GitHub (pinned to 2d3ccc6ba2)

Solutions

  1. Pass a plain integer string exactly as shown in the REVISION column of helm history (e.g. "3")
  2. Validate with strconv.Atoi in the caller/UI before invoking Rollback and reject bad input early
  3. Default the prompt to the previous revision fetched from HelmHistory.Table when the field is empty

Example fix

// before
err := h.Rollback(ctx, path, rev) // rev may be "" or "latest"

// after
rev = strings.TrimSpace(rev)
if _, err := strconv.Atoi(rev); err != nil {
    return fmt.Errorf("invalid revision %q: use a number from helm history", rev)
}
err := h.Rollback(ctx, path, rev)
Defensive patterns

Strategy: validation

Validate before calling

rev = strings.TrimSpace(rev)
if _, err := strconv.Atoi(rev); err != nil {
    // reject before calling Rollback
    return fmt.Errorf("revision %q is not a number (see helm history)", rev)
}

Type guard

func isValidRevision(rev string) bool {
    _, err := strconv.Atoi(strings.TrimSpace(rev))
    return err == nil
}

Try / catch

if err := h.Rollback(ctx, path, rev); err != nil {
    if strings.Contains(err.Error(), "could not convert revision") {
        // bad input: surface to user, do not retry
    }
}

Prevention

When it happens

Trigger: Calling HelmHistory.Rollback(ctx, path, rev) with rev that is not a base-10 integer: empty string, "latest", "1.2", a release name, or a value with surrounding whitespace passed straight from a UI prompt.

Common situations: User types the revision by hand in the k9s helm rollback prompt and leaves it blank or enters the release name; callers forwarding a git SHA/tag instead of the numeric REVISION column; UI fields handed to the DAO unvalidated.

Related errors


AI-assisted analysis of derailed/k9s@2d3ccc6ba2 (2026-08-15). Data as JSON: /api/errors/4869fe7652854d12. Report an issue: GitHub.