mislav/hub · error

Can't parse range %s..%s

Error message

Can't parse range %s..%s

What it means

NewRange() reads merge-base/heads via a git command expected to output exactly two lines (the two endpoints of the range) and builds a Range{A,B}. When the output doesn't have exactly 2 lines, the library can't parse the range and throws this error naming a..b.

Source

Thrown at git/git.go:175

	output, err := listCmd.Output()
	if err != nil {
		return nil, fmt.Errorf("Can't load rev-list for %s", ref)
	}

	return outputLines(output), nil
}

func NewRange(a, b string) (*Range, error) {
	parseCmd := gitCmd("rev-parse", "-q", a, b)
	parseCmd.Stderr = nil
	output, err := parseCmd.Output()
	if err != nil {
		return nil, err
	}

	lines := outputLines(output)
	if len(lines) != 2 {
		return nil, fmt.Errorf("Can't parse range %s..%s", a, b)
	}
	return &Range{lines[0], lines[1]}, nil
}

type Range struct {
	A string
	B string
}

func (r *Range) IsIdentical() bool {
	return strings.EqualFold(r.A, r.B)
}

func (r *Range) IsAncestor() bool {
	cmd := gitCmd("merge-base", "--is-ancestor", r.A, r.B)
	return cmd.Success()
}

View on GitHub (pinned to 5c547ed804)

Solutions

  1. Ensure both a and b exist: git rev-parse a b
  2. Fetch the remote branch before computing the range
  3. Check the two refs differ; same-commit ranges are meaningless
  4. Inspect raw `git merge-base`/`rev-list` output to see the real state

Example fix

// before
rng, err := git.NewRange(base, head)
// after
if shaA, err := git.Ref(base); err != nil || shaA == mustRef(head) {
    return fmt.Errorf("invalid or identical refs %s..%s", base, head)
}
rng, err := git.NewRange(base, head)
Defensive patterns

Strategy: validation

Validate before calling

shaA, errA := exec.Command("git", "rev-parse", a).Output()
shaB, errB := exec.Command("git", "rev-parse", b).Output()
if errA != nil || errB != nil || bytes.Equal(bytes.TrimSpace(shaA), bytes.TrimSpace(shaB)) {
    return fmt.Errorf("invalid or degenerate range %s..%s", a, b)
}

Try / catch

rng, err := git.NewRange(a, b)
if err != nil {
    return fmt.Errorf("cannot parse range %s..%s; verify both refs exist and differ", a, b)
}

Prevention

When it happens

Trigger: Calling git.NewRange(a, b) (via sync) when the underlying git command yields 0, 1, or 3+ lines — typically because one of the refs is invalid, points to the same commit, or output parsing assumptions break on unusual repo states.

Common situations: Comparing a branch with itself; refs that don't exist locally (no fetch); empty repositories with no commits; refs resolving to identical commits producing degenerate output.

Related errors


AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01). Data as JSON: /api/errors/4dfa5ad2920b1a8a. Report an issue: GitHub.