{"record":{"id":"cae22c6fbdfc0d0d","repo":"rust-lang/rust","slug":"the-existing-file-doesn-t-match-what-reuse-repo","errorCode":null,"errorMessage":"The existing {} file doesn't match what REUSE reports.","messagePattern":"The existing (.+?) file doesn't match what REUSE reports\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/tools/collect-license-metadata/src/main.rs","lineNumber":59,"sourceCode":"    let output = serde_json::json!({\n        \"files\": crate::path_tree::expand_interned_licenses(tree, &interner)\n    });\n\n    if only_check {\n        println!(\"loading existing license information\");\n        let existing = std::fs::read_to_string(&dest).with_context(|| {\n            format!(\"Failed to read existing license JSON at {}\", dest.display())\n        })?;\n        let existing_json: serde_json::Value =\n            serde_json::from_str(&existing).with_context(|| {\n                format!(\"Failed to read existing license JSON at {}\", dest.display())\n            })?;\n        if existing_json != output {\n            eprintln!(\"The existing {} file is out of date.\", dest.display());\n            eprintln!(\"Run ./x run collect-license-metadata to update it.\");\n            eprintln!(\"Diff:\");\n            diff_text(&existing, &serde_json::to_string_pretty(&output).unwrap());\n            anyhow::bail!(\"The existing {} file doesn't match what REUSE reports.\", dest.display());\n        }\n        println!(\"license information matches\");\n    } else {\n        if let Some(parent) = dest.parent() {\n            std::fs::create_dir_all(parent)?;\n        }\n        std::fs::write(&dest, &serde_json::to_vec_pretty(&output)?)?;\n        println!(\"license information written to {}\", dest.display());\n    }\n\n    Ok(())\n}\n","sourceCodeStart":41,"sourceCodeEnd":72,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/collect-license-metadata/src/main.rs#L41-L72","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run `./x run collect-license-metadata` (without ONLY_CHECK) locally to regenerate the JSON, then commit the updated file.","Review the diff printed by the tool to confirm the changes are expected license-metadata updates.","Ensure your local REUSE version matches the one CI uses (see the PR links printed in error 134), to avoid format-driven false diffs.","Re-run with ONLY_CHECK to confirm the file now matches."],"exampleFix":"// before (CI check failed)\n$ ONLY_CHECK=1 DEST=... collect-license-metadata\nError: The existing ...json file doesn't match what REUSE reports.\n\n// after\n$ ./x run collect-license-metadata   # regenerate\n$ git add <license-json> && git commit","handlingStrategy":"validation","validationCode":"// In a pre-commit hook, compare committed JSON vs fresh REUSE output before pushing.\nlet existing = std::fs::read(&dest)?;\nlet fresh = serde_json::to_vec(&output)?;\nif existing != fresh {\n    eprintln!(\"License metadata is stale; run ./x run collect-license-metadata\");\n    std::process::exit(1);\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = run_check_mode() {\n    if e.to_string().contains(\"doesn't match what REUSE reports\") {\n        eprintln!(\"{e:#}\");\n        eprintln!(\"Regenerate with: ./x run collect-license-metadata\");\n    }\n    std::process::exit(1);\n}","preventionTips":["Always run ./x run collect-license-metadata after changing file license headers, then commit the JSON.","Use the same REUSE version locally as CI to avoid format-driven drift.","Run the ONLY_CHECK mode locally before pushing."],"tags":["collect-license-metadata","reuse","licensing","ci-check"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}