google-gemini/gemini-cli · error · Error

Empty body while downloading ${endpoint}: ${response.status}

Error message

Empty body while downloading ${endpoint}: ${response.status} - ${response.statusText}

What it means

Thrown when the download fetch returns response.ok === true but response.body is null/empty. This is an anomalous server/proxy response where a success status was sent without a readable body stream.

Source

Thrown at packages/cli/src/ui/commands/setupGithubCommand.ts:145

          method: 'GET',
          dispatcher: proxy ? new ProxyAgent(proxy) : undefined,
          /* eslint-disable @typescript-eslint/no-unsafe-type-assertion */
          signal: (
            AbortSignal as unknown as {
              any: (signals: AbortSignal[]) => AbortSignal;
            }
          ).any([AbortSignal.timeout(30_000), abortController.signal]),
          /* eslint-enable @typescript-eslint/no-unsafe-type-assertion */
        } as RequestInit);

        if (!response.ok) {
          throw new Error(
            `Invalid response code downloading ${endpoint}: ${response.status} - ${response.statusText}`,
          );
        }
        const body = response.body;
        if (!body) {
          throw new Error(
            `Empty body while downloading ${endpoint}: ${response.status} - ${response.statusText}`,
          );
        }

        const destination = path.resolve(
          targetDir,
          path.basename(fileBasename),
        );

        const fileStream = fs.createWriteStream(destination, {
          mode: 0o644, // -rw-r--r--, user(rw), group(r), other(r)
          flags: 'w', // write and overwrite
          flush: true,
        });

        await body.pipeTo(Writable.toWeb(fileStream));
      })(),
    );

View on GitHub (pinned to 5024443c72)

Solutions

  1. Retry the /setup-github command — empty-body anomalies are usually transient.
  2. If a proxy is configured (config.getProxy()), verify it forwards bodies correctly or temporarily bypass it.
  3. Retry when not rate-limited; confirm the endpoint is reachable directly.
Defensive patterns

Strategy: retry

Validate before calling

async function hasBody(endpoint: string, proxy?: string): Promise<boolean> {
  const res = await fetch(endpoint, { dispatcher: proxy ? new ProxyAgent(proxy) : undefined, signal: AbortSignal.timeout(10_000) } as RequestInit);
  return res.ok && !!res.body;
}

Type guard

function isEmptyBodyError(e: unknown): boolean {
  return e instanceof Error && /Empty body while downloading/.test(e.message);
}

Try / catch

for (let attempt = 1; attempt <= 3; attempt++) {
  try { await runSetupGithub(ctx); break; }
  catch (e) {
    if (e instanceof Error && /Empty body while downloading/.test(e.message) && attempt < 3) continue;
    throw e;
  }
}

Prevention

When it happens

Trigger: fetch resolves with a 2xx status yet response.body is undefined/null, so there is nothing to pipe to the destination file.

Common situations: An intermediary proxy or CDN returned a success status with an empty body; a transient server anomaly; a redirect mishandled by the proxy such that the body is dropped.

Related errors


AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12). Data as JSON: /api/errors/5106a36983d540f9. Report an issue: GitHub.