{"record":{"id":"a6bb878bd05914d8","repo":"swc-project/swc","slug":"failed-to-write-to-temp-file","errorCode":null,"errorMessage":"failed to write to temp file","messagePattern":"failed to write to temp file","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_testing/src/lib.rs","lineNumber":664,"sourceCode":"\n        if success_cache.exists() {\n            println!(\"Cache: success\");\n            return Ok(());\n        }\n    }\n\n    let tmp_dir = tempdir_in(&root).expect(\"failed to create a temp directory\");\n    create_dir_all(&tmp_dir).unwrap();\n\n    let path = tmp_dir.path().join(format!(\"{hash}.test.js\"));\n\n    let mut tmp = OpenOptions::new()\n        .create(true)\n        .truncate(true)\n        .write(true)\n        .open(&path)\n        .expect(\"failed to create a temp file\");\n    write!(tmp, \"{src}\").expect(\"failed to write to temp file\");\n    tmp.flush().unwrap();\n\n    let test_runner_path = find_executable(\"mocha\").expect(\"failed to find `mocha` from path\");\n\n    let mut base_cmd = if cfg!(target_os = \"windows\") {\n        let mut c = Command::new(\"cmd\");\n        c.arg(\"/C\").arg(&test_runner_path);\n        c\n    } else {\n        Command::new(&test_runner_path)\n    };\n\n    let output = base_cmd\n        .arg(format!(\"{}\", path.display()))\n        .arg(\"--color\")\n        .current_dir(root)\n        .output()\n        .expect(\"failed to run mocha\");","sourceCodeStart":646,"sourceCodeEnd":682,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_testing/src/lib.rs#L646-L682","documentation":"Immediately after creating the temp file, `exec_with_node_test_runner` writes the transformed source with `write!(tmp, \"{src}\")`. The `expect(\"failed to write to temp file\")` panics when the write itself fails: the filesystem filled up (ENOSPC), a quota was hit mid-write, or the file handle became invalid.","triggerScenarios":"Execution tests running on a full disk or quota-limited volume where the (potentially large, since it embeds the whole transformed bundle) test file cannot be fully written; flaky mounts (network filesystems, overlayfs under memory pressure).","commonSituations":"Build agents whose disks fill during large test batches; container overlay filesystems hitting the size limit; per-user quotas exceeded in shared CI.","solutions":["Check disk space (`df -h $CARGO_TARGET_DIR`) and free space or raise the quota.","Clean the scratch area and cargo caches (`cargo clean`, remove `$CARGO_TARGET_DIR/swc-es-exec-testing`) to reclaim room.","On overlayfs/container limits, raise the container's writable-layer size or bind-mount a larger volume at the target dir.","Skip execution tests with `EXEC=0` on space-constrained runners."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn disk_has_space(p: &std::path::Path) -> bool {\n    // Simplest portable check: write a small file and read it back.\n    let probe = p.join(\".space-probe\");\n    let ok = std::fs::write(&probe, vec![0u8; 1024]).is_ok();\n    let _ = std::fs::remove_file(&probe);\n    ok\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep build disks below capacity; large bundles make the generated .test.js files big.","Periodically clean $CARGO_TARGET_DIR/swc-es-exec-testing (it is scratch/cache).","Set EXEC=0 on quota-limited runners where writes may fail mid-file."],"tags":["test-harness","temp-file","disk-full","io-error","swc"],"backgroundTag":"temp-file-write-failed","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}