Description
Currently if one implements a custom RemoteCallbacks.get_credentials()
and in the process of returning the credentials to the caller throws any Exception, that Exception is ignored and will be replaced by a generic GitError
exception, limiting any custom exception handling.
The code that does this seems to be in the remote.py. To be more precise here in the RemoteCallbacks class.
try:
ccred = get_credentials(credentials, url, username, allowed)
cred_out[0] = ccred[0]
except Passthrough:
return C.GIT_PASSTHROUGH
except Exception as e:
self._stored_exception = e
return C.GIT_EUSER
It stores the error into _stored_exception
but simply returns -7
to the caller.
The calling function then usually will pass that error code to the generic check_error()
function of the errors.py
module. However, the actual Exception stored in _stored_exception
is never processed there. Instead, it simply raises a GitError
with the message err -7 (no message provided)
.
It's unclear how a custom RemoteCallbacks is supposed to perform exception handling when the desired handling is to "bubble the error upwards the stack" where it would be handled and it's unclear why the exception is stored but never re-raised or atleast it's message used to inform the caller about the actual error.
E.g. if someone implements RemoteCallbacks like this:
class MyCallbacks(RemoteCallbacks):
def credentials(self, url, username_from_url, allowed_types):
raise Exception("handle me higher up in the stack!")
and calls it like this:
try:
pygit2.clone_repository("ssh://github.com/libgit2/pygit2", "pygit2.git", callbacks=MyCallbacks())
except GitError ex:
print(ex)
except Exception as ex:
print(f"custom exception handled here: {ex}")
One would expect the output to be:
custom exception handled here: handle me higher up in the stack!
While we actually get:
err -7 (no message provided)