rust-lang/rust · error · anyhow::Error

The existing {} file doesn't match what REUSE reports.

Error message

The existing {} file doesn't match what REUSE reports.

What it means

Thrown by collect-license-metadata when ONLY_CHECK is set and the JSON already written at DEST does not equal the freshly computed REUSE output. The tool prints a diff of the two before bailing, so the developer can see exactly which files' license metadata drifted. This is the CI guard that catches unregenerated license-metadata files.

Source

Thrown at src/tools/collect-license-metadata/src/main.rs:59

    let output = serde_json::json!({
        "files": crate::path_tree::expand_interned_licenses(tree, &interner)
    });

    if only_check {
        println!("loading existing license information");
        let existing = std::fs::read_to_string(&dest).with_context(|| {
            format!("Failed to read existing license JSON at {}", dest.display())
        })?;
        let existing_json: serde_json::Value =
            serde_json::from_str(&existing).with_context(|| {
                format!("Failed to read existing license JSON at {}", dest.display())
            })?;
        if existing_json != output {
            eprintln!("The existing {} file is out of date.", dest.display());
            eprintln!("Run ./x run collect-license-metadata to update it.");
            eprintln!("Diff:");
            diff_text(&existing, &serde_json::to_string_pretty(&output).unwrap());
            anyhow::bail!("The existing {} file doesn't match what REUSE reports.", dest.display());
        }
        println!("license information matches");
    } else {
        if let Some(parent) = dest.parent() {
            std::fs::create_dir_all(parent)?;
        }
        std::fs::write(&dest, &serde_json::to_vec_pretty(&output)?)?;
        println!("license information written to {}", dest.display());
    }

    Ok(())
}

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Run `./x run collect-license-metadata` (without ONLY_CHECK) locally to regenerate the JSON, then commit the updated file.
  2. Review the diff printed by the tool to confirm the changes are expected license-metadata updates.
  3. Ensure your local REUSE version matches the one CI uses (see the PR links printed in error 134), to avoid format-driven false diffs.
  4. Re-run with ONLY_CHECK to confirm the file now matches.

Example fix

// before (CI check failed)
$ ONLY_CHECK=1 DEST=... collect-license-metadata
Error: The existing ...json file doesn't match what REUSE reports.

// after
$ ./x run collect-license-metadata   # regenerate
$ git add <license-json> && git commit
Defensive patterns

Strategy: validation

Validate before calling

// In a pre-commit hook, compare committed JSON vs fresh REUSE output before pushing.
let existing = std::fs::read(&dest)?;
let fresh = serde_json::to_vec(&output)?;
if existing != fresh {
    eprintln!("License metadata is stale; run ./x run collect-license-metadata");
    std::process::exit(1);
}

Try / catch

if let Err(e) = run_check_mode() {
    if e.to_string().contains("doesn't match what REUSE reports") {
        eprintln!("{e:#}");
        eprintln!("Regenerate with: ./x run collect-license-metadata");
    }
    std::process::exit(1);
}

Prevention

When it happens

Trigger: A license/copyright header was added, removed, or changed in a tracked file but `x run collect-license-metadata` was not re-run to regenerate the committed JSON; REUSE version changed its output format or heuristics; a file's REUSE annotations drifted from its committed metadata.

Common situations: A PR modifies file headers without updating the committed license JSON; upgrading REUSE changes how it infers LicenseConcluded; CI enforces ONLY_CHECK and the developer forgot to regenerate.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/cae22c6fbdfc0d0d. Report an issue: GitHub.