affaan-m/ECC · error · FalError

download declares an invalid or excessive size

Error message

download declares an invalid or excessive size

What it means

download() reads the Content-Length header and rejects the transfer before writing anything if the declared size is negative, non-numeric, or larger than MAX_DOWNLOAD_BYTES. This guards against servers lying about size and against allocating for absurdly large payloads.

Solutions

  1. Verify the requested asset is the intended one (small media file, not a bulk export)
  2. Retry the download; a transient proxy may have injected a bogus header
  3. If the file is legitimately larger, raise MAX_DOWNLOAD_BYTES consciously and re-check disk space
  4. Serve via a host that returns accurate Content-Length headers

Example fix

// before
 FalError: download declares an invalid or excessive size
// after
 resp = urllib.request.urlopen(url)
 size = int(resp.headers["Content-Length"])
 assert 0 <= size <= MAX_DOWNLOAD_BYTES
Defensive patterns

Strategy: try-catch

Validate before calling

import urllib.request
req = urllib.request.Request(url, method="HEAD")
cl = urllib.request.urlopen(req, timeout=30).headers.get("Content-Length")
if cl is not None and int(cl) > MAX_DOWNLOAD_BYTES: skip_download()

Try / catch

try:
    download(url, dest)
except FalError as e:
    if "invalid or excessive size" in str(e):
        log.warning("bad Content-Length from %s", host); handle_unreachable(url)

Prevention

When it happens

Trigger: Server sends a Content-Length greater than MAX_DOWNLOAD_BYTES, or a malformed value (e.g. '12 MB', negative) that fails int() or range validation.

Common situations: Proxied/misconfigured servers emitting non-numeric Content-Length headers; downloading an unexpectedly huge generation result; a broken intermediary reporting a padded length.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/0496ccc57f531b7f. Report an issue: GitHub.

Appendix: source

Thrown at skills/taste-distillation/scripts/taste/falapi.py:701

    if is_dry_run():
        dest.parent.mkdir(parents=True, exist_ok=True)
        dest.write_bytes(b"taste-forge dry-run placeholder\n")
        log.info("[dry-run] would download from %s", safe_url(url))
        return dest

    require_live()
    _validate_download_url(url)
    dest.parent.mkdir(parents=True, exist_ok=True)
    log.info("downloading from %s", safe_url(url))
    req = urllib.request.Request(url, headers={"User-Agent": "taste-forge"})
    opener = urllib.request.build_opener(_SafeRedirect())
    temporary = None
    try:
        with opener.open(req, timeout=300) as resp:
            declared = getattr(resp, "headers", {}).get("Content-Length")
            expected = int(declared) if declared is not None else None
            if expected is not None and not 0 <= expected <= MAX_DOWNLOAD_BYTES:
                raise FalError("download declares an invalid or excessive size")
            with tempfile.NamedTemporaryFile(dir=dest.parent, prefix=".taste-download-",
                                             delete=False) as fh:
                temporary = Path(fh.name)
                total = 0
                while True:
                    chunk = resp.read(min(1024 * 1024, MAX_DOWNLOAD_BYTES - total + 1))
                    if not chunk:
                        break
                    total += len(chunk)
                    if total > MAX_DOWNLOAD_BYTES:
                        raise FalError("download exceeds maximum allowed size")
                    fh.write(chunk)
                if expected is not None and total != expected:
                    raise FalError("download length does not match declared size")
        os.replace(temporary, dest)
        temporary = None
    except FalError:
        raise

View on GitHub (pinned to 8321021c54)