rust-lang / git2-rs

libgit2 bindings for Rust
https://docs.rs/git2
Apache License 2.0
1.68k stars 385 forks source link

Runtime error if zlib-ng feature is missing #849

Open konstin opened 2 years ago

konstin commented 2 years ago

If zlib-ng is enabled through any other dependency but the git2/zlib-ng-compat feature is missing a error reading from the zlib stream; class=Zlib (5). is shown at runtime. This error is very hard to debug because there is no indication that this is caused by zlib-ng. Minimal example:

[package]
name = "git-repro"
version = "0.1.0"
edition = "2021"

[dependencies]
git2 = "0.14.4"
# To enable zlib-ng-compat for the zig build
libssh2-sys = { version = "0.2.23" }

[features]
default = ["vendored"]
vendored = ["git2/vendored-libgit2", "git2/vendored-openssl"]
zlib-ng-compat = ["libssh2-sys/zlib-ng-compat"]
use git2::Repository;

fn main() {
    Repository::clone(
        "https://github.com/IQTLabs/hypothesis-bio",
        "hypothesis-bio",
    )
    .unwrap();
    println!("Hello, world!");
}

Fails (Error { code: -1, klass: 5, message: "error reading from the zlib stream" }):

cargo run --features vendored --features zlib-ng-compat

Passed:

cargo run --features vendored