{"record":{"id":"2cbc64ba46415df8","repo":"swc-project/swc","slug":"failed-to-execute","errorCode":null,"errorMessage":"failed to execute:\n{}\n{}","messagePattern":"failed to execute:\n(.+?)\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_testing/src/lib.rs","lineNumber":90,"sourceCode":"\n    let mut c = Command::new(\"node\");\n\n    if opts.module {\n        c.arg(\"--input-type=module\");\n    } else {\n        c.arg(\"--input-type=commonjs\");\n    }\n\n    c.arg(\"-e\").arg(js_code);\n\n    for arg in opts.args {\n        c.arg(arg);\n    }\n\n    let output = c.output().context(\"failed to execute output of minifier\")?;\n\n    if !output.status.success() {\n        bail!(\n            \"failed to execute:\\n{}\\n{}\",\n            String::from_utf8_lossy(&output.stdout),\n            String::from_utf8_lossy(&output.stderr)\n        )\n    }\n\n    String::from_utf8(output.stdout).context(\"output is not utf8\")\n}\n\n/// Writes through a temporary path so parallel test threads never observe a\n/// partially-written cache file.\nfn write_cache_file(cache_path: &Path, bytes: &[u8]) -> Result<()> {\n    let cache_dir = cache_path\n        .parent()\n        .context(\"cache path should have a parent directory\")?;\n    let write_id = CACHE_WRITE_ID.fetch_add(1, Ordering::Relaxed);\n    let tmp_path = cache_dir.join(format!(\n        \".{}.{}.tmp\",","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_testing/src/lib.rs#L72-L108","documentation":"swc_ecma_testing's execution helper runs minified/transpiled JS by spawning a node process (`node --input-type=commonjs -e <code>` plus extra args) and checking the exit status. When node exits nonzero, it bails with 'failed to execute' followed by the child's captured stdout and stderr. The error is test-harness level: the produced code itself crashed or failed assertions at runtime under node.","triggerScenarios":"Calling the test executor (e.g. via default_executor/ RuntimeExecutor::new(NodeExecutor::default().await)) on minified output whose runtime behavior throws, references missing globals/modules, or fails an assertion; also when extra opts.args pass node flags node rejects.","commonSituations":"Minifier/debug output regression: the minified bundle behaves differently from the original (dropped this-binding, inlined constants, broken helpers); test environment missing node on PATH or an incompatible node version; runtime dependencies not installed in the test cwd.","solutions":["Read the embedded stderr in the message: it is the actual node error (stack trace, assertion failure) and points at the failing code","Reproduce by extracting the stdout/stderr code block into a file and running node on it directly to debug the runtime failure","If the failure is a minifier-caused behavior change, minimize the case and report/fix it in swc rather than skipping the test","Ensure node is on PATH with a supported version and any required runtime deps are installed where the test runs"],"exampleFix":"// before: assertion inside executed code fails silently\nlet output = executor.run(\"assert.strictEqual(add(1,2),4)\".into()).await?; // add(1,2)==3\n\n// after: correct the expectation (or the minified output) so the code exits 0\nlet output = executor.run(\"assert.strictEqual(add(1,2),3)\".into()).await?;","handlingStrategy":"try-catch","validationCode":"// Skip execution when the environment cannot run node\nimport { spawnSync } from 'node:child_process';\nconst nodeOk = spawnSync('node', ['--version'], { stdio: 'ignore' }).status === 0;","typeGuard":null,"tryCatchPattern":"let out = executor.run(js_code).await;\nif out.is_err() {\n    // error body embeds child stdout+stderr; log it verbatim for diagnosis\n    eprintln!(\"node execution failed: {out:?}\");\n}","preventionTips":["Ensure `node` is on PATH and versions match the test matrix before running swc_ecma_testing suites","Install runtime dependencies of test fixtures in the working directory","Treat a failure here as a behavioral bug signal: minimize and upstream it instead of ignoring"],"tags":["testing","node-execution","minifier","runtime-failure","swc-ecma-testing"],"backgroundTag":"child-process-execution-failed","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}