{"record":{"id":"2a8d40cb522cb6a4","repo":"swc-project/swc","slug":"message-run-cargo-codegen-helpers-and-commit","errorCode":null,"errorMessage":"{message}; run `cargo codegen helpers` and commit the generated helper artifacts","messagePattern":"(.+?); run `cargo codegen helpers` and commit the generated helper artifacts","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"tools/generate-code/src/main.rs","lineNumber":174,"sourceCode":"        let committed_path = &committed_files[&path];\n        let committed = fs::read(committed_path)\n            .with_context(|| format!(\"failed to read generated artifact: {committed_path:?}\"))?;\n        let generated = fs::read(&generated_path)\n            .with_context(|| format!(\"failed to read generated artifact: {generated_path:?}\"))?;\n\n        if committed != generated {\n            return Err(stale_helper_artifacts(format_args!(\n                \"generated helper artifact `{}` is stale\",\n                path.display()\n            )));\n        }\n    }\n\n    Ok(())\n}\n\nfn stale_helper_artifacts(message: std::fmt::Arguments<'_>) -> anyhow::Error {\n    anyhow!(\"{message}; run `cargo codegen helpers` and commit the generated helper artifacts\")\n}\n\nfn collect_files(root: &Path) -> Result<BTreeMap<PathBuf, PathBuf>> {\n    let mut files = BTreeMap::new();\n    collect_files_inner(root, root, &mut files)?;\n    Ok(files)\n}\n\nfn collect_files_inner(\n    root: &Path,\n    dir: &Path,\n    files: &mut BTreeMap<PathBuf, PathBuf>,\n) -> Result<()> {\n    for entry in fs::read_dir(dir)\n        .with_context(|| format!(\"failed to read generated artifact directory: {dir:?}\"))?\n    {\n        let entry = entry?;\n        let path = entry.path();","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/tools/generate-code/src/main.rs#L156-L192","documentation":"Guard error from tools/generate-code (run via cargo codegen helpers): it regenerates the inline helper artifacts and compares them byte-for-byte with the committed files; any difference means the checked-in helpers are stale relative to the generator/templates. The message names the first stale file and instructs the fix - regenerate and commit.","triggerScenarios":"A PR modifies helper templates, the generator, or formatting but does not run `cargo codegen helpers`; or a contributor edits a generated helper file by hand; or codegen output changes across Rust/toolchain versions.","commonSituations":"CI codegen-consistency checks failing after touching crates/swc_ecma_transforms (or the generator in tools/generate-code); rebasing across a commit that changed generated output.","solutions":["Run `cargo codegen helpers` at repo root","Commit the regenerated artifacts together with the change that made them stale","Never hand-edit generated helper files; change templates and regenerate instead","If CI still fails, check that rustfmt/cargo-codegen versions match the repo's pinned toolchain"],"exampleFix":"# before: CI reports stale helper artifact\n$ git commit -m \"update helper template\"\n\n# after\n$ cargo codegen helpers\n$ git add crates/swc_ecma_transforms/src/helpers\n$ git commit -m \"update helper template + regenerate helpers\"","handlingStrategy":"validation","validationCode":"# Shell: verify artifacts are fresh before pushing\ncargo codegen helpers\ngit diff --exit-code -- crates/swc_ecma_transforms \\\n  || echo 'stale helper artifacts: run cargo codegen helpers and commit'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `cargo codegen helpers` in the same commit that touches generator/templates","Add a CI step that regenerates and diffs, failing on any delta","Never hand-edit generated helpers - fix the template and regenerate"],"tags":["swc","codegen","ci","developer-tooling","generated-code"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}