gleam-lang/gleam · error
should create archive
Error message
should create archive
What it means
In `create_tar_archive_sets_proper_permissions`, the call to the archive-creation helper ends with `.expect("should create archive")`. If building the gzipped tar archive fails (I/O error while writing the in-memory buffer, invalid entry path, etc.), the test panics with this message. Creation is expected to be infallible for the well-formed fixtures used.
Solutions
- Inspect the Err inside create_tar_archive: print it instead of expecting to see the real cause.
- Verify every OutputFile path is a valid relative tar path (no `..`, no leading `/`).
- Check that Content bytes/paths in the fixture match what the function supports.
- If the function legitimately can fail, change it to return Result and assert on the error message.
Example fix
// before
.expect("should create archive");
// after
.unwrap_or_else(|err| panic!("should create archive: {err}")); Defensive patterns
Strategy: try-catch
Validate before calling
// Validate entry paths before archiving
for f in files {
assert!(!f.path.starts_with('/') && !f.path.components().any(|c| c == ".."), "invalid tar path: {}", f.path);
} Try / catch
let archive = create_tar_archive(files)
.unwrap_or_else(|err| panic!("should create archive: {err}")); Prevention
- Inspect the underlying Err rather than hiding it behind a bare expect
- Validate all entry paths are relative and free of `..` components before archiving
- Keep fixtures aligned with what the archive writer supports
- Test create_tar_archive's error paths explicitly in unit tests
When it happens
Trigger: The `create_tar_archive` helper returns Err while compressing the OutputFile list — e.g. an entry path rejected by the tar writer, an I/O failure on the underlying Vec<u8> writer (compiler-cli/src/fs/tests.rs:275).
Common situations: Modifying the archive function or fixtures (e.g. adding a file with an unsupported path like `..` components or an absolute path) and seeing the panic; generally only encountered when changing the tar code or its inputs.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14).
Data as JSON: /api/errors/d567f524b3f6db1e.
Report an issue: GitHub.
Appendix: source
Thrown at compiler-cli/src/fs/tests.rs:275
assert!(dest.join("real.txt").exists());
assert!(!dest.join("escape").exists());
}
// https://github.com/gleam-lang/gleam/issues/5992
#[test]
fn create_tar_archive_sets_proper_permissions() {
let compressed_archive = create_tar_archive(vec![
OutputFile {
content: Content::Text("Hello".into()),
path: "./wibble.txt".into(),
},
OutputFile {
content: Content::Binary(vec![11, 6, 7]),
path: "./wobble.bin".into(),
},
])
.expect("should create archive");
let decoder = flate2::read::GzDecoder::new(Cursor::new(compressed_archive));
let mut archive = tar::Archive::new(decoder);
for entry in archive.entries().expect("archive entries") {
let entry = entry.expect("archive entry");
let mode = entry.header().mode().expect("entry mode");
let entry_path = entry.path().expect("entry path");
let path_str = entry_path.to_str().expect("path string");
assert_eq!(mode, 0o600, "entry {path_str} has unexpected mode")
}
}
View on GitHub (pinned to 15b07c7830)