gastownhall/beads · error

end must be >= start

Error message

end must be >= start

What it means

`parseRange` also enforces that the range is ascending: the parsed `end` must be greater than or equal to `start`. A range like `5-2` describes an empty/inverted slice of the 1-based step list, so `bd mol current` rejects it rather than returning nothing.

Source

Thrown at cmd/bd/mol_current.go:707

// Returns 1-based indices (start=1 means first step).
func parseRange(rangeStr string) (start, end int, err error) {
	parts := strings.Split(rangeStr, "-")
	if len(parts) != 2 {
		return 0, 0, fmt.Errorf("expected format 'start-end' (e.g., '1-50')")
	}
	start, err = strconv.Atoi(strings.TrimSpace(parts[0]))
	if err != nil {
		return 0, 0, fmt.Errorf("invalid start: %w", err)
	}
	end, err = strconv.Atoi(strings.TrimSpace(parts[1]))
	if err != nil {
		return 0, 0, fmt.Errorf("invalid end: %w", err)
	}
	if start < 1 {
		return 0, 0, fmt.Errorf("start must be >= 1")
	}
	if end < start {
		return 0, 0, fmt.Errorf("end must be >= start")
	}
	return start, end, nil
}

// filterStepsByRange filters steps to a 1-based range [start, end].
func filterStepsByRange(steps []*StepStatus, start, end int) []*StepStatus {
	// Convert to 0-based indices
	startIdx := start - 1
	endIdx := end

	if startIdx >= len(steps) {
		return nil
	}
	if endIdx > len(steps) {
		endIdx = len(steps)
	}
	return steps[startIdx:endIdx]
}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Swap the endpoints so the smaller number comes first: `--range 3-7` instead of `--range 7-3`.
  2. If the endpoints come from variables, verify their order before interpolation, or sort them in the script.
  3. If you only want a single step, give a one-step range like `--range 3-3` rather than an inverted pair.

Example fix

// before
bd mol current --range 7-3
// after
bd mol current --range 3-7
Defensive patterns

Strategy: validation

Validate before calling

// shell: normalize order before invoking bd
START=7; END=3
(( START > END )) && { TMP=$START; START=$END; END=$TMP; }
bd mol current --range "$START-$END"

Type guard

func validRange(s, e int) bool { return s >= 1 && e >= s }

Prevention

When it happens

Trigger: Invoking `bd mol current` (or `runMolCurrentProxiedServer`) with `--range` where the first number is larger than the second, e.g. `--range 7-3`. The message surfaces from the `if end < start` check in `parseRange`.

Common situations: Shell variables used in the wrong order (`--range $END-$START`); hardcoded ranges edited by hand after steps were reordered; template variables substituted so start/end swap positions.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/fbab20a3f32f030f. Report an issue: GitHub.