larksuite/cli · error

parse range end: %w

Error message

parse range end: %w

What it means

parseContentRange validated the range start but the end bound of `bytes start-end/total` failed strconv.ParseInt; the wrapped error is strconv's. The server's Content-Range header has a non-integer end value for the partial response.

Source

Thrown at extension/download/download.go:698

	}
	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)
	}
	if end >= total {
		return contentRange{}, fmt.Errorf("invalid content range: end %d is outside total %d", end, total)
	}
	return contentRange{start: start, end: end, total: total}, nil

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Inspect raw headers to see the exact malformed value.
  2. Fix the server/proxy generating the header.
  3. Validate the endpoint with curl -r 0-99 -D- URL.
  4. Avoid third-party middleboxes that rewrite response headers.

Example fix

// before
// Content-Range: bytes 0-nine/500
// after
// Content-Range: bytes 0-499/500
Defensive patterns

Strategy: try-catch

Validate before calling

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

Try / catch

cr, err := parseContentRange(header)
if err != nil {
	return fmt.Errorf("malformed Content-Range end in %q: %w", header, err)
}

Prevention

When it happens

Trigger: openPartial or openNext received something like 'bytes 0-nine/500' or an end value beyond int64.

Common situations: Buggy or malicious servers; proxies that inject characters; hand-written mock responses with placeholder text.

Related errors


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