swc-project/swc · error
failed to create file ({}) for writing data of the failed as
Error message
failed to create file ({}) for writing data of the failed assertion: {} What it means
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.
Source
Thrown at crates/testing/src/lib.rs:222
let cp = self.cm.lookup_char_pos(span.lo());
let line = cp.line;
let column = cp.col.0 + 1;
line * 10000 + column
});
match result {
Ok(res) => Ok(res),
Err(()) => Err(errs),
}
}
}
fn write_to_file(path: &Path, content: &str) {
File::create(path)
.unwrap_or_else(|err| {
panic!(
"failed to create file ({}) for writing data of the failed assertion: {}",
path.display(),
err
)
})
.write_all(content.as_bytes())
.expect("failed to write data of the failed assertion")
}
pub fn print_left_right(left: &dyn Debug, right: &dyn Debug) -> String {
fn print(t: &dyn Debug) -> String {
let s = format!("{t:#?}");
// Replace 'Span { lo: BytePos(0), hi: BytePos(0), ctxt: #0 }' with '_'
let s = {
static RE: Lazy<Regex> =
Lazy::new(|| Regex::new("Span \\{[\\a-zA-Z0#:\\(\\)]*\\}").unwrap());
View on GitHub (pinned to 5176682b65)
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
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at crates/testing/src/lib.rs:222 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/788deabe24e8bcca.
Report an issue: GitHub.