larksuite/cli · error

parse range start: %w

Error message

parse range start: %w

What it means

parseContentRange successfully split a `bytes start-end/total` Content-Range header into bounds, but the start bound is not a valid base-10 integer; the wrapped error is strconv's. It means the server emitted a syntactically malformed range start in a partial response.

Source

Thrown at extension/download/download.go:694

	}
	unit, spec, found := strings.Cut(header, " ")
	if !found || !strings.EqualFold(unit, "bytes") {
		return contentRange{}, fmt.Errorf("unsupported content-range: %q", header)
	}
	parts := strings.SplitN(strings.TrimSpace(spec), "/", 2)
	if len(parts) != 2 || parts[0] == "" || parts[1] == "" || parts[0] == "*" {
		return contentRange{}, fmt.Errorf("unsupported content-range: %q", header)
	}
	if parts[1] == "*" {
		return contentRange{}, fmt.Errorf("unknown total size in content-range: %q", header)
	}
	bounds := strings.SplitN(parts[0], "-", 2)
	if len(bounds) != 2 || bounds[0] == "" || bounds[1] == "" {
		return contentRange{}, fmt.Errorf("unsupported content-range: %q", header)
	}
	start, err := strconv.ParseInt(bounds[0], 10, 64)
	if err != nil {
		return contentRange{}, fmt.Errorf("parse range start: %w", err)
	}
	end, err := strconv.ParseInt(bounds[1], 10, 64)
	if err != nil {
		return contentRange{}, fmt.Errorf("parse range end: %w", err)
	}
	total, err := strconv.ParseInt(parts[1], 10, 64)
	if err != nil {
		return contentRange{}, fmt.Errorf("parse total size: %w", err)
	}
	if total <= 0 {
		return contentRange{}, fmt.Errorf("invalid total size: %d", total)
	}
	if start < 0 || end < 0 {
		return contentRange{}, fmt.Errorf("invalid negative content range: %d-%d", start, end)
	}
	if start > end {
		return contentRange{}, fmt.Errorf("invalid content range: start %d is after end %d", start, end)
	}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Dump the raw response headers and inspect the Content-Range value.
  2. Fix or bypass the component producing the corrupted header.
  3. Test the endpoint with curl -r 0-0 -D- to confirm a numeric start.
  4. Retry the download; transient corruption may clear.

Example fix

// before
// Content-Range: bytes abc-99/500
// after
// Content-Range: bytes 0-99/500
Defensive patterns

Strategy: try-catch

Validate before calling

func numericRange(h string) bool {
	_, spec, _ := strings.Cut(h, " ")
	startEnd, _, _ := strings.Cut(spec, "/")
	start, _, _ := strings.Cut(startEnd, "-")
	_, err := strconv.ParseInt(start, 10, 64)
	return err == nil
}

Try / catch

cr, err := parseContentRange(header)
var perr *strconv.NumError
if errors.As(err, &perr) {
	return fmt.Errorf("corrupt Content-Range %q: %w", header, err)
}

Prevention

When it happens

Trigger: openPartial or openNext received something like 'bytes abc-99/500' or a start exceeding int64.

Common situations: Corrupted response headers from buggy servers or proxies; tests with fake header values; binary garbage injected by a misconfigured gateway.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/4ee3d4429bd63e54. Report an issue: GitHub.