helm/helm · error

file does not exist

Error message

file does not exist

What it means

parser.listItem (pkg/strvals/parser.go:335) rejects negative list indexes while processing the main --set/--set-json grammar. keyIndex() parses the bracket text with strconv.Atoi, which accepts '-1'; listItem then refuses it before touching the list. This is the error users actually see for 'a[-1]=v' in --set.

Source

Thrown at internal/chart/v3/lint/rules/values.go:51

// they are only tested for well-formedness.
//
// If additional values are supplied, they are coalesced into the values in values.yaml.
func ValuesWithOverrides(linter *support.Linter, valueOverrides map[string]any, skipSchemaValidation bool) {
	file := "values.yaml"
	vf := filepath.Join(linter.ChartDir, file)
	fileExists := linter.RunLinterRule(support.InfoSev, file, validateValuesFileExistence(vf))

	if !fileExists {
		return
	}

	linter.RunLinterRule(support.ErrorSev, file, validateValuesFile(vf, valueOverrides, skipSchemaValidation))
}

func validateValuesFileExistence(valuesPath string) error {
	_, err := os.Stat(valuesPath)
	if err != nil {
		return errors.New("file does not exist")
	}
	return nil
}

func validateValuesFile(valuesPath string, overrides map[string]any, skipSchemaValidation bool) error {
	values, err := common.ReadValuesFile(valuesPath)
	if err != nil {
		return fmt.Errorf("unable to parse YAML: %w", err)
	}

	// Helm 3.0.0 carried over the values linting from Helm 2.x, which only tests the top
	// level values against the top-level expectations. Subchart values are not linted.
	// We could change that. For now, though, we retain that strategy, and thus can
	// coalesce tables (like reuse-values does) instead of doing the full chart
	// CoalesceValues
	coalescedValues := util.CoalesceTables(make(map[string]any, len(overrides)), overrides)
	coalescedValues = util.CoalesceTables(coalescedValues, values)

View on GitHub (pinned to 2a29f1770b)

Solutions

  1. Replace negative indexes with explicit non-negative 0-based ones
  2. Compute the real index from the list length before building the expression
  3. Sanitize generated expressions: reject any \[-\d+\] bracket

Example fix

# before
helm install mychart --set hosts[-1]=example.com
# after
helm install mychart --set hosts[0]=example.com
Defensive patterns

Strategy: validation

Validate before calling

var negIdx = regexp.MustCompile(`\[-\d+\]`)
func hasNegativeIndex(setLine string) bool { return negIdx.MatchString(setLine) }

Try / catch

if err := strvals.Parse(s); err != nil && strings.Contains(err.Error(), "index not allowed") {
    return fmt.Errorf("negative list index unsupported: %w", err)
}

Prevention

When it happens

Trigger: strvals.Parse("a[-1]=v"), strvals.ParseJSON("a[-1]=null", dest), nested variants like "a.b[-1]=v".

Common situations: Python/Ruby-style negative indexing habits; loop counters or env interpolation that evaluate to a negative number; migrating scripts from tools that allow -1 as last element.

Related errors


AI-assisted analysis of helm/helm@2a29f1770b (2026-08-15). Data as JSON: /api/errors/ce8b3dbdf3c0ea33. Report an issue: GitHub.