swc-project/swc · error · anyhow::Error
Failed to run cargo command
Error message
Failed to run cargo command
What it means
xtask's run_cmd helper spawns a child process (cargo, git, etc.), inherits stdin, waits for exit, and bails with this generic message whenever the child's exit status is non-success. The command line was already printed to stderr ('Running ...'), so the actual failure details live in the child's own output just above this error.
Source
Thrown at xtask/src/util/mod.rs:29
where
F: FnOnce() -> Result<Ret>,
{
op()
}
pub fn repository_root() -> Result<PathBuf> {
let dir = env::var("CARGO_MANIFEST_DIR").context("failed to get manifest dir")?;
Ok(Path::new(&*dir).parent().unwrap().to_path_buf())
}
pub fn run_cmd(cmd: &mut Command) -> Result<()> {
eprintln!("Running {:?}", *cmd);
cmd.stdin(Stdio::inherit());
let status = cmd.status()?;
if !status.success() {
anyhow::bail!("Failed to run cargo command");
}
Ok(())
}
pub fn get_commit_for_core_version(version: &str, last: bool) -> Result<String> {
wrap(|| {
eprintln!("Getting commit for swc_core@v{version}");
// We need to get the list of commits and pull requests which changed the
// version of swc_core.
let git_rev_list = Command::new("git")
.current_dir(repository_root()?)
.arg("rev-list")
.arg("--branches")
.arg("main")
.arg("--")
.arg("Cargo.lock")View on GitHub (pinned to d7d7434666)
Solutions
- Scroll up to the child command's own stderr/stdout - the real error is there; fix that underlying failure
- Re-run the exact 'Running ...' command printed just above to reproduce it directly
- For CI, ensure submodules are initialized (git submodule update --init --recursive) and the pinned toolchain is installed before invoking xtask
Example fix
# before: opaque failure $ cargo xtask some-task Error: Failed to run cargo command # after: reproduce the printed command to see the cause $ cargo build -p swc_core --all-features # whatever 'Running ...' showed # fix the underlying error, then re-run the xtask
Defensive patterns
Strategy: try-catch
Validate before calling
# Shell: preflight the common causes before invoking xtask git submodule update --init --recursive cargo --version && rustc --version # match pinned toolchain
Try / catch
# Shell: run xtask so the child's real error stays visible, then surface exit code
cargo xtask <task> 2>&1 | tee /tmp/xtask.log
status=${PIPESTATUS[0]}
if [ "$status" -ne 0 ]; then
echo "xtask failed; the failing child command is the last 'Running ...' line above"
exit "$status"
fi Prevention
- Read the child command's output above the error - the generic message carries no cause
- Re-run the printed 'Running ...' command directly to iterate on the real failure
- Keep submodules and the pinned toolchain installed before running any xtask command
When it happens
Trigger: Any xtask driver (bump-core-version, release, etc.) whose underlying cargo build/test/doc or git invocation exits nonzero - compile error in the workspace, failing test, git conflict, missing tool.
Common situations: Running cargo xtask commands locally on a dirty or broken tree; CI jobs invoking xtask where a nested cargo step fails; missing git submodules making a nested cargo invocation fail.
Related errors
- {message}; run `cargo codegen helpers` and commit the genera
- 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/73f807cbc43e7ebf.
Report an issue: GitHub.