wagoodman/dive · error
highestUserWastedPercent config value is outside allowed ran
Error message
highestUserWastedPercent config value is outside allowed range (0-1), given '%f'
What it means
Returned when highestUserWastedPercent parses as a float but is outside [0, 1]. The metric is a fraction of user-layer bytes wasted; 0.1 means 10%. Values above 1 (like 10 for '10%') or negative values are rejected during rule construction.
Source
Thrown at cmd/dive/cli/internal/command/ci/rules.go:171
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) {
if analysis.WastedUserPercent > r.threshold {
return RuleFailed, fmt.Sprintf(
"too many bytes wasted, relative to the user bytes added (%%-user-wasted-bytes=%2.2f > threshold=%v)",
analysis.WastedUserPercent, r.threshold)
}View on GitHub (pinned to d6c691947f)
Solutions
- Convert percent to a fraction: 20% -> "0.2"
- Audit all three CI thresholds for consistent fraction notation
- If you meant to make the rule never fail, use the disabled sentinel rather than an out-of-range number
- Add a config sanity check to CI that rejects values > 1 in fraction fields
Example fix
# before rules: highestUserWastedPercent: "20" # after rules: highestUserWastedPercent: "0.2"
Defensive patterns
Strategy: validation
Validate before calling
f, err := strconv.ParseFloat(cfg.HighestUserWastedPercent, 64)
if err == nil && (f < 0 || f > 1) {
return fmt.Errorf("highestUserWastedPercent %f outside [0,1]; use a fraction like 0.2", f)
} 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(), "outside allowed range") {
// suggest converting percent to fraction in user-facing output
}
if err != nil { return err } Prevention
- Keep all ratio thresholds in [0,1] fraction form
- Add unit tests that reject >1 values in CI config parsers
- When a policy says N%, write N/100 in the config
When it happens
Trigger: highestUserWastedPercent: "0.1" passes; "10" (percent-style), "1.2", or "-1" fail the range check right after ParseFloat succeeds.
Common situations: The classic percent-vs-fraction mistake: copying a policy that says 'fail above 20% wasted' and writing 20 instead of 0.2; incrementing thresholds without renormalizing to fractions.
Related errors
- %s config value is outside allowed range (0-1), given '%f'
- invalid %s config value, given %q: %v
- invalid highestWastedBytes config value, given %q: %v
- invalid highestUserWastedPercent config value, given %q: %v
- evaluation failed
AI-assisted analysis of wagoodman/dive@d6c691947f (2026-08-15).
Data as JSON: /api/errors/11704dbbb63b9f5b.
Report an issue: GitHub.