wagoodman/dive · error

invalid highestUserWastedPercent config value, given %q: %v

Error message

invalid highestUserWastedPercent config value, given %q: %v

What it means

Returned when the highestUserWastedPercent rule value fails strconv.ParseFloat. This rule bounds the fraction of wasted bytes attributable to user-added (non-reference) layers, and like the efficiency rule it must be a plain float string; percent notation and comma decimals are rejected at config-load time.

Source

Thrown at cmd/dive/cli/internal/command/ci/rules.go:166

func (r *HighestWastedBytesRule) Evaluate(analysis *image.Analysis) (RuleStatus, string) {
	if analysis.WastedBytes > r.threshold {
		return RuleFailed, fmt.Sprintf(
			"too many bytes wasted (wasted-bytes=%d > threshold=%v)",
			analysis.WastedBytes, r.threshold)
	}
	return RulePassed, ""
}

// NewHighestUserWastedPercentRule creates a new rule to check percentage of wasted bytes
func NewHighestUserWastedPercentRule(configValue string) (Rule, error) {
	if isRuleDisabled(configValue) {
		return DisabledRule(ciKeyHighestUserWastedPercent), nil
	}

	threshold, err := strconv.ParseFloat(configValue, 64)
	if err != nil {
		return nil, fmt.Errorf("invalid highestUserWastedPercent config value, given %q: %v",
			configValue, err)
	}

	if threshold < 0 || threshold > 1 {
		return nil, fmt.Errorf("highestUserWastedPercent config value is outside allowed range (0-1), given '%f'",
			threshold)
	}

	return &HighestUserWastedPercentRule{
		BaseRule: BaseRule{
			key:         ciKeyHighestUserWastedPercent,
			configValue: configValue,
		},
		threshold: threshold,
	}, nil
}

func (r *HighestUserWastedPercentRule) Evaluate(analysis *image.Analysis) (RuleStatus, string) {

View on GitHub (pinned to d6c691947f)

Solutions

  1. Write the value as a fraction between 0 and 1, e.g. "0.4" for 40%
  2. Strip %, commas, and template placeholders from the config value
  3. Validate CI config files in a lint step (dive with a dummy image) before merging
  4. Use the disabled sentinel if this rule should not apply

Example fix

# before
rules:
  highestUserWastedPercent: "40%"

# after
rules:
  highestUserWastedPercent: "0.4"
Defensive patterns

Strategy: validation

Validate before calling

if _, err := strconv.ParseFloat(cfg.HighestUserWastedPercent, 64); err != nil {
    return fmt.Errorf("highestUserWastedPercent must be a decimal fraction like 0.4: %w", err)
}

Type guard

func isValidFraction(s string) bool {
    f, err := strconv.ParseFloat(s, 64)
    return err == nil && f >= 0 && f <= 1
}

Try / catch

rule, err := ci.NewHighestUserWastedPercentRule(value)
if err != nil && strings.Contains(err.Error(), "invalid highestUserWastedPercent") {
    // config-format error: show expected form ("0.4" for 40%)
}
if err != nil { return err }

Prevention

When it happens

Trigger: highestUserWastedPercent set to "0.4" works; "40%", "0,4", or a non-numeric placeholder string fails ParseFloat and raises this error before analysis begins.

Common situations: Teams writing whole-percent values from style guides; configs edited in locales with comma decimals; template variables left unfilled ("{{MAX_WASTED}}") reaching production.

Related errors


AI-assisted analysis of wagoodman/dive@d6c691947f (2026-08-15). Data as JSON: /api/errors/657005e1710a63e5. Report an issue: GitHub.