swc-project/swc · warning · anyhow::Error
{message}; run `cargo codegen helpers` and commit the genera
Error message
{message}; run `cargo codegen helpers` and commit the generated helper artifacts What it means
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.
Source
Thrown at tools/generate-code/src/main.rs:174
let committed_path = &committed_files[&path];
let committed = fs::read(committed_path)
.with_context(|| format!("failed to read generated artifact: {committed_path:?}"))?;
let generated = fs::read(&generated_path)
.with_context(|| format!("failed to read generated artifact: {generated_path:?}"))?;
if committed != generated {
return Err(stale_helper_artifacts(format_args!(
"generated helper artifact `{}` is stale",
path.display()
)));
}
}
Ok(())
}
fn stale_helper_artifacts(message: std::fmt::Arguments<'_>) -> anyhow::Error {
anyhow!("{message}; run `cargo codegen helpers` and commit the generated helper artifacts")
}
fn collect_files(root: &Path) -> Result<BTreeMap<PathBuf, PathBuf>> {
let mut files = BTreeMap::new();
collect_files_inner(root, root, &mut files)?;
Ok(files)
}
fn collect_files_inner(
root: &Path,
dir: &Path,
files: &mut BTreeMap<PathBuf, PathBuf>,
) -> Result<()> {
for entry in fs::read_dir(dir)
.with_context(|| format!("failed to read generated artifact directory: {dir:?}"))?
{
let entry = entry?;
let path = entry.path();View on GitHub (pinned to d7d7434666)
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
Example fix
# before: CI reports stale helper artifact $ git commit -m "update helper template" # after $ cargo codegen helpers $ git add crates/swc_ecma_transforms/src/helpers $ git commit -m "update helper template + regenerate helpers"
Defensive patterns
Strategy: validation
Validate before calling
# Shell: verify artifacts are fresh before pushing cargo codegen helpers git diff --exit-code -- crates/swc_ecma_transforms \ || echo 'stale helper artifacts: run cargo codegen helpers and commit'
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to run cargo command
- module string names unimplemented
- module string names unimplemented
- module string names unimplemented
- module string names unimplemented
AI-assisted analysis of swc-project/swc@d7d7434666 (2026-08-16).
Data as JSON: /api/errors/2a8d40cb522cb6a4.
Report an issue: GitHub.