{"record":{"id":"73f807cbc43e7ebf","repo":"swc-project/swc","slug":"failed-to-run-cargo-command","errorCode":null,"errorMessage":"Failed to run cargo command","messagePattern":"Failed to run cargo command","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"xtask/src/util/mod.rs","lineNumber":29,"sourceCode":"where\n    F: FnOnce() -> Result<Ret>,\n{\n    op()\n}\n\npub fn repository_root() -> Result<PathBuf> {\n    let dir = env::var(\"CARGO_MANIFEST_DIR\").context(\"failed to get manifest dir\")?;\n    Ok(Path::new(&*dir).parent().unwrap().to_path_buf())\n}\n\npub fn run_cmd(cmd: &mut Command) -> Result<()> {\n    eprintln!(\"Running {:?}\", *cmd);\n    cmd.stdin(Stdio::inherit());\n\n    let status = cmd.status()?;\n\n    if !status.success() {\n        anyhow::bail!(\"Failed to run cargo command\");\n    }\n\n    Ok(())\n}\n\npub fn get_commit_for_core_version(version: &str, last: bool) -> Result<String> {\n    wrap(|| {\n        eprintln!(\"Getting commit for swc_core@v{version}\");\n\n        // We need to get the list of commits and pull requests which changed the\n        // version of swc_core.\n        let git_rev_list = Command::new(\"git\")\n            .current_dir(repository_root()?)\n            .arg(\"rev-list\")\n            .arg(\"--branches\")\n            .arg(\"main\")\n            .arg(\"--\")\n            .arg(\"Cargo.lock\")","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/xtask/src/util/mod.rs#L11-L47","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before: opaque failure\n$ cargo xtask some-task\nError: Failed to run cargo command\n\n# after: reproduce the printed command to see the cause\n$ cargo build -p swc_core --all-features   # whatever 'Running ...' showed\n# fix the underlying error, then re-run the xtask","handlingStrategy":"try-catch","validationCode":"# Shell: preflight the common causes before invoking xtask\ngit submodule update --init --recursive\ncargo --version && rustc --version  # match pinned toolchain","typeGuard":null,"tryCatchPattern":"# Shell: run xtask so the child's real error stays visible, then surface exit code\ncargo xtask <task> 2>&1 | tee /tmp/xtask.log\nstatus=${PIPESTATUS[0]}\nif [ \"$status\" -ne 0 ]; then\n  echo \"xtask failed; the failing child command is the last 'Running ...' line above\"\n  exit \"$status\"\nfi","preventionTips":["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"],"tags":["swc","xtask","build","process","developer-tooling"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}