{"record":{"id":"c100a721dec58c58","repo":"swc-project/swc","slug":"failed-to-create-a-temp-directory","errorCode":null,"errorMessage":"failed to create a temp directory","messagePattern":"failed to create a temp directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_testing/src/lib.rs","lineNumber":653,"sourceCode":"\nfn exec_with_node_test_runner(src: &str) -> Result<(), ()> {\n    let root = CARGO_TARGET_DIR.join(\"swc-es-exec-testing\");\n\n    create_dir_all(&root).expect(\"failed to create parent directory for temp directory\");\n\n    let hash = calc_hash(src);\n    let success_cache = root.join(format!(\"{hash}.success\"));\n\n    if env::var(\"SWC_CACHE_TEST\").unwrap_or_default() == \"1\" {\n        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);","sourceCodeStart":635,"sourceCodeEnd":671,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_testing/src/lib.rs#L635-L671","documentation":"After ensuring the scratch root exists, `exec_with_node_test_runner` creates a temp directory inside it with `tempdir_in(&root)`. The `expect(\"failed to create a temp directory\")` panics when tempfile cannot create that directory: permission denied on the parent, disk/inode exhaustion, or platform temp-creation limits (e.g. name collisions or EMFILE on some systems).","triggerScenarios":"Execution tests running with a read-only or root-owned `$CARGO_TARGET_DIR/swc-es-exec-testing`, out-of-space or out-of-inode filesystems, or heavy parallel test execution hitting file-descriptor limits.","commonSituations":"Same environments as the directory-creation failure: locked-down CI sandboxes, mixed-ownership target dirs after sudo runs, full build disks.","solutions":["Fix permissions/ownership of `$CARGO_TARGET_DIR/swc-es-exec-testing` so the test user can create directories.","Check free space and inodes (`df -h`, `df -i`) and clean the build disk.","Reduce test parallelism if fd/inode exhaustion is implicated, or raise ulimits in the CI job.","As a workaround for constrained envs, disable execution tests with `EXEC=0`."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn can_create_dirs_under(p: &std::path::Path) -> bool {\n    let probe = p.join(\".dir-probe\");\n    std::fs::create_dir(&probe).is_ok() && {\n        let _ = std::fs::remove_dir(&probe);\n        true\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify directory-creation rights on the target dir in CI setup scripts.","Monitor disk and inode usage on build agents (df -h / df -i).","Avoid mixing users when running cargo to prevent ownership mismatches under target/."],"tags":["test-harness","temp-dir","filesystem","permissions","swc"],"backgroundTag":"temp-dir-creation-failed","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}