gastownhall/beads · error

invalid range format %q: expected start..end

Error message

invalid range format %q: expected start..end

What it means

ParseRange() matched the trimmed expression against rangePattern (start..end) and it did not match, so the expression is not a valid 'start..end' range. The offending expression is quoted in the error.

Source

Thrown at internal/formula/range.go:51

// ParseRange parses a range expression and evaluates it using the given variables.
// Returns the start and end values of the range.
//
// Examples:
//
//	ParseRange("1..10", nil)           -> {1, 10}
//	ParseRange("1..2^3", nil)          -> {1, 8}
//	ParseRange("1..2^{n}", {"n":"3"})  -> {1, 8}
func ParseRange(expr string, vars map[string]string) (*RangeSpec, error) {
	expr = strings.TrimSpace(expr)
	if expr == "" {
		return nil, fmt.Errorf("empty range expression")
	}

	// Parse start..end format
	m := rangePattern.FindStringSubmatch(expr)
	if m == nil {
		return nil, fmt.Errorf("invalid range format %q: expected start..end", expr)
	}

	startExpr := strings.TrimSpace(m[1])
	endExpr := strings.TrimSpace(m[2])

	// Evaluate start expression
	start, err := EvaluateExpr(startExpr, vars)
	if err != nil {
		return nil, fmt.Errorf("evaluating range start %q: %w", startExpr, err)
	}

	// Evaluate end expression
	end, err := EvaluateExpr(endExpr, vars)
	if err != nil {
		return nil, fmt.Errorf("evaluating range end %q: %w", endExpr, err)
	}

	return &RangeSpec{Start: start, End: end}, nil

View on GitHub (pinned to 71377f2769)

Solutions

  1. Rewrite the expression in start..end form with the double-dot separator, e.g. "1..10".
  2. Check for unexpanded template variables in the string and ensure the vars map supplies them.
  3. Validate the range string (regex ^[^.]+\.\.[^.]+$ style check) before passing it to ParseRange.

Example fix

# before
range: "1-10"

# after
range: "1..10"
Defensive patterns

Strategy: validation

Validate before calling

var rangeRe = regexp.MustCompile(`^[^.]+\.\.[^.]+$`)
if !rangeRe.MatchString(strings.TrimSpace(rawRange)) {
	return fmt.Errorf("range %q must be start..end", rawRange)
}

Try / catch

spec, err := ParseRange(expr, vars)
if err != nil {
	if strings.Contains(err.Error(), "expected start..end") {
		// show the correct syntax next to the bad value
	}
}

Prevention

When it happens

Trigger: Calling ParseRange("1-10", vars), ParseRange("1 to 10", vars), ParseRange("..5", vars) or any expression lacking the literal '..' separator with parseable start and end sides; expandLoopWithVars passing a malformed range string from a molecule.

Common situations: Using a single '-' or '...' instead of '..'; copying range syntax from another language (Python's range(1,10) or Ruby's 1..10 written as 1,10); template placeholders not fully expanded leaving stray braces that break the regex.

Related errors


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