{"record":{"id":"7a2e761888eb4989","repo":"swc-project/swc","slug":"failed-to-create-a-temp-file","errorCode":null,"errorMessage":"failed to create a temp file","messagePattern":"failed to create a temp file","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_testing/src/lib.rs","lineNumber":663,"sourceCode":"        println!(\"Trying cache as `SWC_CACHE_TEST` is `1`\");\n\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()","sourceCodeStart":645,"sourceCodeEnd":681,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_testing/src/lib.rs#L645-L681","documentation":"`exec_with_node_test_runner` writes the generated mocha test file with `OpenOptions::new().create(true).truncate(true).write(true).open(&path)`. The `expect(\"failed to create a temp file\")` panics when opening `{tmpdir}/{hash}.test.js` for writing fails — almost always permission or disk-space issues on the temp directory just created, since the parent directory already exists at this point.","triggerScenarios":"Execution tests where the temp dir exists but is not writable (ACLs, SELinux denials), the filesystem filled up between dir creation and file creation, or antivirus/mandatory-locking environments blocking file creation on Windows.","commonSituations":"Hardened CI images with restrictive ACLs on the cargo target dir; disk-full agents; Windows environments where another process holds a lock on a same-named leftover file.","solutions":["Verify you can create files inside `$CARGO_TARGET_DIR/swc-es-exec-testing/` manually; fix ACLs/ownership if not.","Clear stale contents of the scratch dir (`rm -rf $CARGO_TARGET_DIR/swc-es-exec-testing`) to remove collided/locked files; it is a pure cache/scratch area.","Free disk space if ENOSPC, and disable execution tests (`EXEC=0`) in environments that cannot write there."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn can_create_files_under(p: &std::path::Path) -> bool {\n    let probe = p.join(\".file-probe\");\n    std::fs::write(&probe, b\"\").is_ok() && {\n        let _ = std::fs::remove_file(&probe);\n        true\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run a writable-probe check on $CARGO_TARGET_DIR/swc-es-exec-testing in CI before cargo test.","Clear the scratch dir when stale/locked files from crashed runs remain.","On Windows, exclude the target dir from antivirus scanning to avoid creation blocks."],"tags":["test-harness","temp-file","filesystem","permissions","swc"],"backgroundTag":"temp-file-creation-failed","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}