{"record":{"id":"788deabe24e8bcca","repo":"swc-project/swc","slug":"failed-to-create-file-for-writing-data-of-the","errorCode":null,"errorMessage":"failed to create file ({}) for writing data of the failed assertion: {}","messagePattern":"failed to create file \\((.+?)\\) for writing data of the failed assertion: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/testing/src/lib.rs","lineNumber":222,"sourceCode":"            let cp = self.cm.lookup_char_pos(span.lo());\n\n            let line = cp.line;\n            let column = cp.col.0 + 1;\n\n            line * 10000 + column\n        });\n\n        match result {\n            Ok(res) => Ok(res),\n            Err(()) => Err(errs),\n        }\n    }\n}\n\nfn write_to_file(path: &Path, content: &str) {\n    File::create(path)\n        .unwrap_or_else(|err| {\n            panic!(\n                \"failed to create file ({}) for writing data of the failed assertion: {}\",\n                path.display(),\n                err\n            )\n        })\n        .write_all(content.as_bytes())\n        .expect(\"failed to write data of the failed assertion\")\n}\n\npub fn print_left_right(left: &dyn Debug, right: &dyn Debug) -> String {\n    fn print(t: &dyn Debug) -> String {\n        let s = format!(\"{t:#?}\");\n\n        // Replace 'Span { lo: BytePos(0), hi: BytePos(0), ctxt: #0 }' with '_'\n        let s = {\n            static RE: Lazy<Regex> =\n                Lazy::new(|| Regex::new(\"Span \\\\{[\\\\a-zA-Z0#:\\\\(\\\\)]*\\\\}\").unwrap());\n","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/testing/src/lib.rs#L204-L240","documentation":"Raised in `write_to_file` (crates/testing/src/lib.rs:222), called from print_left_right after an assertion failure. When a fixture assertion fails, the harness dumps the left/right values to files under the test-results directory; if File::create fails for that path (permission denied, read-only FS, missing parent directory, sandbox restrictions), this panic replaces the assertion output. The error from File::create, caused by an unwritable results path, is the input at fault.","triggerScenarios":"Thrown at crates/testing/src/lib.rs:222 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check that the target directory exists and is writable before the test run (create it in advance)","Ensure target/swc-test-results is not locked by another process or made read-only by the environment","Make write_to_file degrade gracefully (e.g. print contents to stderr) so the original assertion failure is still visible"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}