Hmbown/CodeWhale · error · Error

Too many redirects while downloading

Error message

Too many redirects while downloading ${url}

What it means

downloadText fetches text bodies (e.g. checksum files) following redirects with a depth counter. Exceeding 10 redirects aborts, since that indicates a redirect loop rather than a legitimate redirect chain.

Solutions

  1. Test the URL with curl -IL and fix the mirror/redirect configuration
  2. Point at the official GitHub release download URL
  3. Retry if transient CDN behavior
Defensive patterns

Strategy: retry

Validate before calling

const res = await fetch(url, { redirect: "manual" });
let hops = 0, loc = res.headers.get("location");
while (loc && hops < 10) { hops++; loc = (await fetch(loc, { redirect: "manual" })).headers.get("location"); }
if (hops > 10) throw new Error(`Redirect loop for ${url}`);

Try / catch

try { text = await checksums(url); } catch (e) { if (/Too many redirects/.test(e.message)) { console.error(`Fix mirror redirect loop: ${url}`); throw e; } throw e; }

Prevention

When it happens

Trigger: checksums() or bundleChecksums() → downloadText on a URL that redirects more than 10 times or loops (e.g. checksums file hosted behind a misconfigured mirror).

Common situations: Custom checksum file URL pointing at a looping proxy; CDN misconfiguration after release publish.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/33e0844939f1a0c3. Report an issue: GitHub.

Appendix: source

Thrown at npm/codewhale/scripts/verify-release-assets.js:108

    );
    req.on("error", reject);
    req.end();
  });
}

async function verifyAsset(url, label) {
  let status = await requestStatus(url, "HEAD");
  if (status === 403 || status === 405) {
    status = await requestStatus(url, "GET");
  }
  if (status < 200 || status >= 400) {
    throw new Error(`${label} returned HTTP ${status} (${url})`);
  }
}

async function downloadText(url, redirects = 0) {
  if (redirects > 10) {
    throw new Error(`Too many redirects while downloading ${url}`);
  }
  const client = url.startsWith("https:") ? https : http;
  return new Promise((resolve, reject) => {
    client
      .get(
        url,
        {
          headers: {
            "User-Agent": "codewhale-npm-release-check",
          },
        },
        (res) => {
          const status = res.statusCode || 0;
          if (status >= 300 && status < 400 && res.headers.location) {
            const next = new URL(res.headers.location, url).toString();
            res.resume();
            resolve(downloadText(next, redirects + 1));
            return;

View on GitHub (pinned to 433685b202)