istio/istio · error

invalid duration

Error message

invalid duration

What it means

bug-report's Duration type implements YAML/JSON unmarshaling: a float64 (JSON number) is cast to time.Duration nanoseconds, a string goes through time.ParseDuration, and any other type (bool, map, list, null-shaped non-null, or integer encoded oddly) yields 'invalid duration'. So the config key is present but has an unusable type.

Source

Thrown at tools/bug-report/pkg/config/config.go:321

func (d *Duration) UnmarshalJSON(b []byte) error {
	var v any
	if err := json.Unmarshal(b, &v); err != nil {
		return err
	}
	switch value := v.(type) {
	case float64:
		*d = Duration(time.Duration(value))
		return nil
	case string:
		tmp, err := time.ParseDuration(value)
		if err != nil {
			return err
		}
		*d = Duration(tmp)
		return nil
	default:
		return errors.New("invalid duration")
	}
}

View on GitHub (pinned to 8dc789c5cf)

Solutions

  1. Use a duration string with units: `wait-timeout: 5m` or `2m30s`.
  2. If using a number, remember it means nanoseconds — prefer strings to avoid surprises.
  3. Remove quotes/structural mistakes so the scalar stays a plain string.

Example fix

# before
wait-timeout: true

# after
wait-timeout: 5m
Defensive patterns

Strategy: type-guard

Validate before calling

value := cfg["wait-timeout"]
switch value.(type) {
case float64, string:
default:
    return fmt.Errorf("wait-timeout must be a number or duration string, got %T", value)
}

Type guard

func isDurationable(v any) bool {
    switch v.(type) {
    case float64, string:
        return true
    }
    return false
}

Try / catch

In custom unmarshalers, pre-check the node kind (scalar number or string) and return a typed error naming the config key; never accept bool/map/list for duration fields.

Prevention

When it happens

Trigger: Writing `wait-timeout: true`, `timeout: [30]`, or `interval: 30` where the YAML scalar resolves to something other than number/string in the bug-report config (tools/bug-report). Numeric values are interpreted as nanoseconds, so `30` becomes 30ns — technically valid but almost certainly unintended.

Common situations: Hand-editing the bug-report YAML with a quoted complex value; templating tools injecting booleans or lists; users writing `5s` correctly but a stray character (e.g. `5s,`) breaking the string parse.

Related errors


AI-assisted analysis of istio/istio@8dc789c5cf (2026-08-15). Data as JSON: /api/errors/41f17c7b45de9698. Report an issue: GitHub.