{"record":{"id":"b295dd2e8763e55f","repo":"swc-project/swc","slug":"failed-to-create-parent-directory-for-temp-directo","errorCode":null,"errorMessage":"failed to create parent directory for temp directory","messagePattern":"failed to create parent directory for temp directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_testing/src/lib.rs","lineNumber":639,"sourceCode":"            src_without_helpers\n        );\n\n        exec_with_node_test_runner(&src).map(|_| {})\n    })\n}\n\nfn calc_hash(s: &str) -> String {\n    let mut hasher = Sha256::new();\n    hasher.update(s.as_bytes());\n    let sum = hasher.finalize();\n\n    hex::encode(sum)\n}\n\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","sourceCodeStart":621,"sourceCodeEnd":657,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_testing/src/lib.rs#L621-L657","documentation":"`exec_with_node_test_runner` (used by execution tests) creates its scratch directory at `$CARGO_TARGET_DIR/swc-es-exec-testing` with `create_dir_all`. The `expect(\"failed to create parent directory for temp directory\")` panics when that `create_dir_all` fails: the target dir (or a parent) is not writable, the disk is full or read-only, or `CARGO_TARGET_DIR` points to an invalid/unavailable location.","triggerScenarios":"Running execution tests (`EXEC != 0`) with CARGO_TARGET_DIR unset/pointing somewhere unwritable, a read-only filesystem (some CI sandboxes, Nix builds without writable paths), exhausted disk quota, or permission changes on target/.","commonSituations":"CI containers running tests as a user without write access to the target dir; root-owned `target/` after running cargo once under sudo; disk-full build agents.","solutions":["Check writability: `touch $CARGO_TARGET_DIR/swc-es-exec-testing/.probe` (create as needed) and fix ownership/permissions (`chown -R $(id -u) target`).","Point CARGO_TARGET_DIR at a writable location when invoking cargo if the default is unusable.","Free disk space / raise the quota if the write fails with ENOSPC.","Skip execution tests (`EXEC=0`) if you only need transform-output tests in a constrained environment."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Ensure the execution-test scratch root is writable before running tests.\nfn exec_scratch_writable() -> bool {\n    let root = std::env::var(\"CARGO_TARGET_DIR\")\n        .map(std::path::PathBuf::from)\n        .unwrap_or_else(|_| std::path::PathBuf::from(\"target\"));\n    let root = root.join(\"swc-es-exec-testing\");\n    std::fs::create_dir_all(&root).is_ok()\n        && {\n            let probe = root.join(\".probe\");\n            std::fs::write(&probe, b\"\").is_ok()\n                && { let _ = std::fs::remove_file(&probe); true }\n        }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the cargo target dir owned by the user running tests (avoid sudo cargo).","Point CARGO_TARGET_DIR at a writable volume in CI.","Skip execution tests (EXEC=0) on read-only filesystems."],"tags":["test-harness","filesystem","permissions","target-dir","swc"],"backgroundTag":"directory-creation-failed","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}