gleam-lang/gleam · error
archive entries
Error message
archive entries
What it means
`.expect("archive entries")` wraps `archive.entries()` when reading back the generated tarball with flate2's GzDecoder. It panics if iterating the archive fails — typically because the compressed bytes are corrupt or not a valid gzipped tar, or an entry header cannot be read.
Solutions
- Verify the archive is gzip-compressed: `file archive.tar.gz` / feed bytes to `tar -tzf`.
- Confirm GzDecoder is the right reader for what create_tar_archive writes (flate2 GzEncoder output).
- Print the underlying error: replace expect with `unwrap_or_else(|e| panic!("archive entries: {e}"))`.
- Regenerate/inspect the archive bytes with an external tool to spot corruption.
Example fix
// before
for entry in archive.entries().expect("archive entries") {
// after
for entry in archive.entries().unwrap_or_else(|e| panic!("archive entries: {e}")) { Defensive patterns
Strategy: try-catch
Validate before calling
// Quick sanity check that the bytes are gzip assert_eq!(&compressed_archive[..2], &[0x1f, 0x8b], "not gzip data");
Try / catch
for entry in archive.entries().unwrap_or_else(|e| panic!("archive entries: {e}")) {
...
} Prevention
- Match decoder to encoder (gzip in -> GzDecoder; plain tar -> no decoder)
- Inspect produced archives with `tar -tzf` when changing writer code
- Verify the compression step is not skipped or double-applied
- Include the underlying io::Error in panic messages for faster diagnosis
When it happens
Trigger: Decoding the produced archive in the test: if `create_tar_archive` produced malformed/corrupt gzip data, or the Cursor contents were truncated/altered, `entries()` returns Err and the expect panics (compiler-cli/src/fs/tests.rs:280).
Common situations: Encountered when the archive writer is changed (e.g. wrong compression, writing raw tar without gzip) or when decode setup (decoder/reader wiring) is modified incorrectly.
Related errors
AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14).
Data as JSON: /api/errors/e2d6021e053143d7.
Report an issue: GitHub.
Appendix: source
Thrown at compiler-cli/src/fs/tests.rs:280
// 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)