Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support libgit2 error message report when assertion failed #517

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion libgit2-sys/lib.rs
Expand Up @@ -7,6 +7,8 @@ extern crate libz_sys as libz;
use libc::{c_char, c_int, c_uchar, c_uint, c_void, size_t};
#[cfg(feature = "ssh")]
use libssh2_sys as libssh2;
use std::ffi::CStr;
use std::ptr;

pub const GIT_OID_RAWSZ: usize = 20;
pub const GIT_OID_HEXSZ: usize = GIT_OID_RAWSZ * 2;
Expand Down Expand Up @@ -3551,7 +3553,25 @@ pub fn init() {
openssl_init();
ssh_init();
let r = git_libgit2_init();
assert!(r >= 0, "couldn't initialize the libgit2 library: {}", r);
if r < 0 {
let git_error = git_error_last();
let mut error_msg: *mut c_char = ptr::null_mut();
if !git_error.is_null() {
error_msg = (*git_error).message;
}
if !error_msg.is_null() {
assert!(
r >= 0,
"couldn't initialize the libgit2 library: {}, error: {}",
r,
CStr::from_ptr(error_msg).to_string_lossy()
);
} else {
assert!(r >= 0, "couldn't initialize the libgit2 library: {}", r);
}
} else {
assert!(r >= 0, "couldn't initialize the libgit2 library: {}", r);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this perhaps be structured to check the return code, and then if it's negative fetch the error message and print it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Will do.

Copy link
Contributor Author

@cosmo0920 cosmo0920 Feb 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've commited 8af51f1 for your suggested comment.


// Note that we intentionally never schedule `git_libgit2_shutdown` to
// get called. There's not really a great time to call that and #276 has
Expand Down