jackwener/OpenCLI · error · CommandExecutionError

Failed to verify downloaded bytes for ${item.filename}

Error message

Failed to verify downloaded bytes for ${item.filename}

What it means

After a successful httpDownload, downloadInstagramMedia verifies result.size is a finite positive number; otherwise it throws this CommandExecutionError. It guards against zero-byte or corrupted files (e.g. the CDN returned an error page or empty body) being silently saved as valid media.

Source

Thrown at clis/instagram/download.js:335

        throw new CliError('RATE_LIMITED', message, 'Wait a few minutes and retry, or switch to a browser session with a warmer Instagram login state.', EXIT_CODES.TEMPFAIL);
    }
    if (result.errorCode === 'PRIVATE_OR_UNAVAILABLE') {
        throw new CommandExecutionError(message, 'Open the post in a logged-in browser session and retry');
    }
    throw new CommandExecutionError(message);
}
async function downloadInstagramMedia(items, outputDir) {
    fs.mkdirSync(outputDir, { recursive: true });
    for (const item of items) {
        const destPath = path.join(outputDir, item.filename);
        const result = await httpDownload(item.url, destPath, {
            timeout: item.type === 'video' ? 120000 : 60000,
        });
        if (!result.success) {
            throw new CommandExecutionError(`Failed to download ${item.filename}: ${result.error || 'unknown error'}`);
        }
        if (!Number.isFinite(result.size) || result.size <= 0) {
            throw new CommandExecutionError(`Failed to verify downloaded bytes for ${item.filename}`);
        }
    }
}
cli({
    site: 'instagram',
    name: 'download',
    access: 'read',
    description: 'Download images and videos from Instagram posts and reels',
    domain: 'www.instagram.com',
    strategy: Strategy.COOKIE,
    navigateBefore: false,
    args: [
        { name: 'url', positional: true, required: true, help: 'Instagram post / reel / tv URL' },
        { name: 'path', default: '~/Downloads/Instagram', help: 'Download directory' },
    ],
    func: async (page, kwargs) => {
        const browserPage = ensurePage(page);
        const target = parseInstagramMediaTarget(String(kwargs.url ?? ''));

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Delete the zero-byte file and re-run the download
  2. Check free disk space in the output directory
  3. Retry — transient CDN issues often resolve
  4. If reproducible, upgrade the CLI or inspect httpDownload for size reporting bugs

Example fix

// after catching, clean up and retry
try {
  await downloadInstagramMedia(mediaItems, savedDir);
} catch (e) {
  if (String(e.message).includes('Failed to verify downloaded bytes')) {
    fs.rmSync(savedDir, { recursive: true, force: true });
  }
  throw e;
}
Defensive patterns

Strategy: validation

Validate before calling

// after download, before trusting the file
const stat = fs.statSync(destPath);
if (!stat.isFile() || stat.size === 0) throw new Error('Downloaded file is empty: ' + destPath);

Type guard

function hasValidSize(result) {
  return Number.isFinite(result.size) && result.size > 0;
}

Try / catch

try {
  await downloadInstagramMedia(items, dir);
} catch (e) {
  if (String(e.message).includes('Failed to verify downloaded bytes')) {
    fs.rmSync(dir, { recursive: true, force: true }); // remove corrupt output
  } else throw e;
}

Prevention

When it happens

Trigger: httpDownload reports success but result.size is 0, negative, or NaN — empty response body, server returned 200 with zero bytes, or the download implementation failed to report written byte count.

Common situations: Instagram CDN returning an empty 200 response; disk-full or quota issues that truncate writes; a bug or interception in httpDownload that doesn't populate size; content-encoding issues producing empty bodies.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/26a0c26a6b1cdcb1. Report an issue: GitHub.