gleam-lang/gleam · error
archive entry
Error message
archive entry
What it means
`.expect("archive entry")` unwraps each individual entry Result while iterating the decoded tar archive. It panics when a specific entry's header cannot be read from the stream — i.e. the archive is truncated or an entry record is malformed, even though the overall entries() iteration started fine.
Solutions
- Surface the real error: replace expect with a panic that includes the entry error.
- Validate the generated archive with `tar -tvzf` to find the malformed entry.
- Check that each OutputFile's content length matches what the tar builder was given (header size vs written bytes).
- Diff against a known-good archive produced before your change to isolate the regression.
Example fix
// before
let entry = entry.expect("archive entry");
// after
let entry = entry.unwrap_or_else(|e| panic!("archive entry: {e}")); Defensive patterns
Strategy: try-catch
Validate before calling
// Validate the whole archive once and report per-entry errors
let entries: Result<Vec<_>, _> = archive.entries().and_then(|it| it.collect());
let entries = entries.unwrap_or_else(|e| panic!("bad archive: {e}")); Try / catch
let entry = entry.unwrap_or_else(|e| panic!("archive entry: {e}")); Prevention
- Ensure header sizes match written content bytes for every tar entry
- Check archives with `tar -tvzf` to detect truncated/malformed records early
- Keep entry data-length bookkeeping in one place in the writer
- Include entry names in error context when unwrapping entry Results
When it happens
Trigger: Reading entry-by-entry in `create_tar_archive_sets_proper_permissions`: a malformed or truncated entry record in the generated archive makes `entry` an Err and the expect panics (compiler-cli/src/fs/tests.rs:281).
Common situations: Happens when the writer produces structurally broken tar records (e.g. entry data length mismatch) or the decode buffer is cut short; usually only seen after changing archive-writing code.
Related errors
AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14).
Data as JSON: /api/errors/1efc7ca79bb16bf4.
Report an issue: GitHub.
Appendix: source
Thrown at compiler-cli/src/fs/tests.rs:281
#[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)