charmbracelet/crush · error

%s: --%s expects a number, got %q

Error message

%s: --%s expects a number, got %q

What it means

parseFlagValue validates float flags via strconv.ParseFloat(v, 64). A value that isn't a valid number after a flagFloat flag causes applyFlags to fail with "<cmd>: --<flag> expects a number, got %q". Like the bool/int variants, this aborts crushrc config construction.

Source

Thrown at internal/shellconfig/flags.go:145

	case flagInt:
		v, err := nextArg(args, i, name)
		if err != nil {
			return nil, 0, err
		}
		n, err := strconv.ParseInt(v, 10, 64)
		if err != nil {
			return nil, 0, fmt.Errorf("%s: --%s expects an integer, got %q", args[0], name, v)
		}
		return n, i + 2, nil

	case flagFloat:
		v, err := nextArg(args, i, name)
		if err != nil {
			return nil, 0, err
		}
		f, err := strconv.ParseFloat(v, 64)
		if err != nil {
			return nil, 0, fmt.Errorf("%s: --%s expects a number, got %q", args[0], name, v)
		}
		return f, i + 2, nil

	case flagKeyValue:
		if i+2 >= len(args) {
			return nil, 0, fmt.Errorf("%s: --%s requires a key and value", args[0], name)
		}
		return [2]string{args[i+1], args[i+2]}, i + 3, nil

	case flagJSONObject:
		v, err := nextArg(args, i, name)
		if err != nil {
			return nil, 0, err
		}
		var object map[string]any
		if err := json.Unmarshal([]byte(v), &object); err != nil || object == nil {
			return nil, 0, fmt.Errorf("%s: --%s expects a JSON object, got %q", args[0], name, v)
		}

View on GitHub (pinned to 7944b8e522)

Solutions

  1. Provide a plain decimal number using a dot as the decimal separator (e.g. 0.7).
  2. Convert percentage/units notation to a plain number (50 not 50%).
  3. Check the flag's declared type; if it's flagInt use an integer instead.
  4. Quote-free plain values only — surrounding shell quoting can introduce stray characters.

Example fix

// before (crushrc)
options --temperature 0,7
// after
options --temperature 0.7
Defensive patterns

Strategy: validation

Validate before calling

func isFloatLiteral(v string) bool {
	_, err := strconv.ParseFloat(v, 64)
	return err == nil
}

Try / catch

err := cfg.Apply(args)
if err != nil && strings.Contains(err.Error(), "expects a number") {
	// show cmd+flag and offending value from the message
}

Prevention

When it happens

Trigger: A crushrc builtin call with e.g. `--temperature high` or `--threshold 0,75` where the flag was declared flagFloat; empty values or values with units (50%).

Common situations: Users writing percentages with %, decimal commas from non-English locales, or named values (high/low) for numeric tuning options like model temperature.

Related errors


AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29). Data as JSON: /api/errors/60d4021f345438a7. Report an issue: GitHub.