biomejs/biome · error

{} has size {}, expected {expected_size}

Error message

{} has size {}, expected {expected_size}

What it means

This error is raised by `Properties::validate` in xtask/codegen/src/unicode.rs:222 when the Unicode data file (fetched from unicode.org or loaded from the local cache) has a byte length that differs from the hard-coded `expected_size`. The size check is an integrity guard: the code generator only trusts a known-good snapshot of Unicode property data, so any file whose total length differs from the pinned expectation is rejected. Note that the file must pass the version check first; a size mismatch means the content changed even if the version line matches.

Source

Thrown at xtask/codegen/src/unicode.rs:222

            .and_then(|properties| properties.validate(expected_version, expected_size))
            .or_else(|_| {
                let fetched = Self::fetch(cache_path, source_url)?
                    .validate(expected_version, expected_size)?;
                fetched.save_cache()?;
                Ok(fetched)
            })
    }

    fn validate(self, expected_version: &str, expected_size: usize) -> Result<Self> {
        anyhow::ensure!(
            self.raw
                .lines()
                .take(10)
                .any(|line| line.contains(expected_version)),
            "{} does not contain Unicode version {expected_version}",
            self.path().display()
        );
        anyhow::ensure!(
            self.raw.len() == expected_size,
            "{} has size {}, expected {expected_size}",
            self.path().display(),
            self.raw.len()
        );

        Ok(self)
    }

    fn path(&self) -> PathBuf {
        xtask_glue::project_root().join(self.cache_path)
    }

    /// Retrieve properties from the unicode website.
    /// # Errors
    /// Return an error if the HTTP request fails.
    fn fetch(cache_path: &'static str, source_url: &str) -> Result<Self> {
        let raw = ureq::get(source_url).call()?.into_body().read_to_string()?;

View on GitHub (pinned to 3835945f06)

Solutions

  1. Delete the stale cache file at the path named in the error (relative to the project root) and re-run codegen so it re-fetches the exact file; if it still mismatches, the upstream file changed
  2. If upstream data legitimately changed, update the `expected_size` argument passed to `Properties::cached_or_fetch` for that property to the new byte length (and bump `expected_version` if needed)
  3. Check git status / `git diff` on the cached file; restore it with `git checkout -- <cache_path>` if it was unintentionally modified (common with autocrlf)
  4. Verify the download is complete and unmodified: compare byte length or checksum of the fetched file against the one published by unicode.org; bypass proxies that rewrite content

Example fix

// before (xtask/codegen/src/unicode.rs, call site)
Properties::cached_or_fetch(
    "xtask/codegen/unicode/UnicodeData.txt",
    UNICODE_DATA_URL,
    "16.0.0",
    1_934_576, // stale size
)?;
// after (re-measure the file: wc -c xtask/codegen/unicode/UnicodeData.txt)
Properties::cached_or_fetch(
    "xtask/codegen/unicode/UnicodeData.txt",
    UNICODE_DATA_URL,
    "16.0.0",
    1_952_104, // new pinned size
)?;
Defensive patterns

Strategy: validation

Validate before calling

use std::fs;
let raw = fs::read_to_string("xtask/codegen/unicode/UnicodeData.txt")?;
if raw.len() != 1_934_576 {
    // stale or modified cache: remove it so codegen re-fetches
    let _ = fs::remove_file("xtask/codegen/unicode/UnicodeData.txt");
}
// Windows users: confirm git isn't converting line endings
// git config core.autocrlf  # should be false/input for this repo

Try / catch

match Properties::cached_or_fetch(CACHE_PATH, URL, VERSION, EXPECTED_SIZE) {
    Ok(props) => generate(props),
    Err(e) if e.to_string().contains("has size") => {
        // size mismatch: drop the cache and retry with a fresh fetch
        let _ = std::fs::remove_file(CACHE_PATH);
        generate(Properties::cached_or_fetch(CACHE_PATH, URL, VERSION, EXPECTED_SIZE)?);
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Running the xtask codegen (`cargo codegen unicode`) when `Properties::cached_or_fetch` obtains data whose `raw.len() != expected_size`. Concretely: (1) a re-fetched Unicode .txt file differs in byte size from the pinned `expected_size` constant (Unicode site updated the file, added/removed code points, changed line endings or trailing newline); (2) the cache file at `cache_path` was hand-edited, truncated, saved with CRLF/LF conversion, or written by a different tool that reformatted it; (3) a proxy/CDN or partial download returned a truncated or modified copy of the file; (4) the repository's checked-in cached file was touched (e.g. git checkout/autocrlf conversion) while the pinned size in the source was not updated.

Common situations: Most often hit after Unicode publishes a revised data file (e.g. a new Unicode version or an update to a property file like UnicodeData.txt) so the byte count no longer matches the constant in xtask/codegen. Also common on Windows with git autocrlf, which converts LF to CRLF in the cached file and changes its length, or after manually editing the cache to test something and forgetting to restore it.

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 biomejs/biome@3835945f06 (2026-09-13). Data as JSON: /api/errors/2bc65be157b7dde9. Report an issue: GitHub.