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 response if the declared size is negative or larger than MAX_DOWNLOAD_BYTES. This prevents allocating/disk-filling downloads for oversized or malformed responses before any bytes are written.

Solutions

  1. Raise MAX_DOWNLOAD_BYTES in falapi.py to accommodate the asset you expect
  2. Download the large asset with your own streaming HTTP client and your own size policy
  3. Check the actual asset size (curl -sI) before downloading to see if the limit is the blocker
  4. If the header is bogus, retry the download — a proxy may have corrupted the response

Example fix

# before
# falapi.py
MAX_DOWNLOAD_BYTES = 512 * 1024 * 1024
# after
MAX_DOWNLOAD_BYTES = 2 * 1024 * 1024 * 1024  # allow larger videos
Defensive patterns

Strategy: validation

Validate before calling

import urllib.request
req = urllib.request.Request(url, method='HEAD')
size = int(urllib.request.urlopen(req).headers.get('Content-Length', 0))
assert 0 <= size <= 512 * 1024 * 1024, 'asset exceeds download limit'

Try / catch

try:
    download(url, dest)
except FalError:
    # stream manually with your own cap
    ...

Prevention

When it happens

Trigger: Server responds with Content-Length exceeding MAX_DOWNLOAD_BYTES (e.g. a huge video), or with a negative/undecodable value that int() accepts as out of bounds (negative sizes). Note: a non-integer Content-Length raises ValueError caught by the generic handler instead.

Common situations: Downloading a long rendered video that legitimately exceeds the configured MAX_DOWNLOAD_BYTES; a misbehaving/proxied server emitting a bogus Content-Length; attempting to download a full mesh sequence bundle rather than a single asset.

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/53337e71edf1b6f0. Report an issue: GitHub.

Appendix: source

Thrown at skills/taste-application/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)