Unexpected Rugged::ZlibError in Commit#header_field
rugged_exception_raise seems to raise the wrong exception after a specific series of method calls.
-
Repository#lookup -
Repository#read_header -
Commit#header_field(with args that will cause an exception)
The final call should raise a RuntimeError afaict, but it actually raises a Rugged::ZlibError.
Here's some tests that demonstrate this behavior.
#563 actually fixes this specific case, because it catches the GIT_ENOTFOUND without calling rugged_exception_check, but it seems like there might be an underlying problem as well that should be fixed.
This is most likely coming from libgit2 internals. It looks like one of these calls is handling an error case but not resetting the error state in libgit2. So the next time rugged_exception_check is called, this stale error state is handled.
Indeed, in commit.c:610 we return an error code, but we do not set an error message, so rugged is grabbing whatever existed just before. The "real" fix would be to add a giterr_set() call here about not finding the header field.
Looks like it's a pattern in libgit2 to return GIT_ENOTFOUND without calling giterr_set(). I guess https://github.com/libgit2/rugged/pull/563 might actually be the correct fix for this bug.