GitoxideLabs/gitoxide · error

Should never see other errors than zlib, but got

Error message

Should never see other errors than zlib, but got {:?}

What it means

This panic fires while an in-memory object's data is being zlib-deflated for a pack entry. The code assumes any I/O error from `std::io::copy` over a `&[u8]` source must carry `ErrorKind::Other`, which the zlib encoder uses for its failures; anything else is considered impossible for a pure in-memory slice and panics with an unreachable.

Solutions

  1. Update gix-pack/gix-zlib so zlib errors always map to ErrorKind::Other, or upgrade the crate
  2. Capture the panic message and report it upstream with the offending object data
  3. Work around by compressing via `gix_zlib::stream::deflate::Write` yourself and handling all error kinds explicitly

Example fix

// before
err => unreachable!("Should never see other errors than zlib, but got {:?}", err),
// after
err => return Err(Error::ZlibDeflate(std::io::Error::new(err.kind(), err))),
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure data is an in-memory slice before building the entry
debug_assert!(obj.data.is_empty() || compression.level().is_some(), "compression level must be valid");

Type guard

fn is_io_other(err: &std::io::Error) -> bool { err.kind() == std::io::ErrorKind::Other }

Try / catch

match result {
    Ok(entry) => entry,
    Err(e) => { log::error!("pack entry deflate failed: {e}"); return Err(e); }
} // plus catch_unwind if calling from FFI or a long-lived writer

Prevention

When it happens

Trigger: Calling `output::Entry::from(&obj)` (pack entry construction during pack writing) while the underlying zlib deflate stream returns an io::Error whose kind is not `Other` — e.g. an io error injected by a custom writer wrapper or an unexpected error propagated from the Vec sink.

Common situations: Rare in practice: writing packs with a gix version whose zlib backend surfaces errors with different ErrorKinds, or wrapping/intercepting writers; virtually never hit with plain in-memory data.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of GitoxideLabs/gitoxide@e73179060b (2026-09-08). Data as JSON: /api/errors/6127a98956bbfb97. Report an issue: GitHub.

Appendix: source

Thrown at gix-pack/src/data/output/entry/mod.rs:157

    /// deflating it with `compression`.
    ///
    /// Note that `git` compresses pack entries with the level configured with `pack.compression`,
    /// whose default is [`Compression::DEFAULT`](gix_zlib::Compression::DEFAULT).
    pub fn from_data(
        count: &output::Count,
        obj: &gix_object::Data<'_>,
        compression: gix_zlib::Compression,
    ) -> Result<Self, Error> {
        Ok(output::Entry {
            id: count.id.to_owned(),
            kind: Kind::Base(obj.kind),
            decompressed_size: obj.data.len(),
            compressed_data: {
                let mut out = gix_zlib::stream::deflate::Write::new(Vec::new(), compression);
                if let Err(err) = std::io::copy(&mut &*obj.data, &mut out) {
                    match err.kind() {
                        std::io::ErrorKind::Other => return Err(Error::ZlibDeflate(err)),
                        err => unreachable!("Should never see other errors than zlib, but got {:?}", err),
                    }
                }
                out.flush()?;
                out.into_inner()
            },
        })
    }

    /// Transform ourselves into a pack entry header which can be written into a pack of `version`.
    ///
    /// `index_to_pack(object_index) -> pack_offset` is a function to convert the base object's index into
    /// the input object array (if each object is numbered) to an offset into the pack.
    /// This information is known to the one calling the method.
    pub fn to_entry_header(
        &self,
        _version: data::Version,
        index_to_base_distance: impl FnOnce(usize) -> u64,
    ) -> data::entry::Header {

View on GitHub (pinned to e73179060b)