rugged icon indicating copy to clipboard operation
rugged copied to clipboard

Unexpected Rugged::ZlibError in Commit#header_field

Open btoews opened this issue 10 years ago • 3 comments

rugged_exception_raise seems to raise the wrong exception after a specific series of method calls.

  1. Repository#lookup
  2. Repository#read_header
  3. 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.

btoews avatar Feb 03 '16 03:02 btoews

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.

arthurschreiber avatar Feb 03 '16 11:02 arthurschreiber

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.

carlosmn avatar Feb 03 '16 17:02 carlosmn

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.

btoews avatar Feb 03 '16 17:02 btoews