gleam-lang/gleam · error

path string

Error message

path string

What it means

This panic comes from `entry_path.to_str().expect("path string")` in create_tar_archive_sets_proper_permissions. The entry path parsed from the tar header contains bytes that are not valid UTF-8, so Path::to_str returns None and the expect panics. It indicates non-ASCII or raw-byte filenames inside the archive.

Solutions

  1. Sanitize/normalize entry names before adding them to the archive so they are always ASCII/UTF-8 relative paths.
  2. In the test, use entry.path().to_string_lossy() instead of to_str().expect to tolerate non-UTF-8 names.
  3. If non-UTF-8 names are possible, assert on the raw OsStr or fail with a descriptive message instead of expect.
  4. Ensure temp dirs used by the test (std::env::temp_dir) resolve to ASCII paths, e.g. override TMPDIR in CI.

Example fix

// before
let path_str = entry_path.to_str().expect("path string");
// after
let path_str = entry_path.to_string_lossy();
Defensive patterns

Strategy: validation

Validate before calling

let path_str = entry_path.to_str();
if path_str.is_none() { eprintln!("skipping non-UTF-8 entry: {:?}", entry_path); }

Type guard

fn is_utf8_path(p: &std::path::Path) -> bool { p.to_str().is_some() }

Try / catch

let path_str = match entry_path.to_str() { Some(s) => s, None => { eprintln!("non-UTF-8 path"); continue; } };

Prevention

When it happens

Trigger: An entry in the tar archive created by create_tar_archive has a filename that is not valid UTF-8 (e.g. OS-specific raw bytes from a temp path or non-ASCII filename), so to_str() returns None.

Common situations: Running tests on systems whose temp directories contain non-ASCII usernames, or after a change that forwards arbitrary source filenames into archive entry names on Windows (where paths can be WTF-8).

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14). Data as JSON: /api/errors/5213ae4fef43b340. Report an issue: GitHub.

Appendix: source

Thrown at compiler-cli/src/fs/tests.rs:284

        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)