-
-
Notifications
You must be signed in to change notification settings - Fork 394
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
RemoteCallbacks exceptions are ignored #996
Comments
As far as I can tell it seems like there would be a bigger refactoring needed to fix this issue propperly. So what about a temporary workaround: implement a Something like: #errors.py
class CustomPygitException(Exception)
'''
Custom exception that will bypass any PyGit2 error handling and bubble up the stack.
Should be extended if custom exceptions are required.
'''
def __init__(self, message):
super().__init__(message)
def check_error(err, io=False):
if err and isinstance(err, CustomPygitException):
raise err
if err >= 0:
return
... If this sounds acceptable let me know and I'll gladly provide the PR. |
Commit cd09686 fixes this for I found there was already a similar mechanism for other callbacks in Thanks! |
Interesting. Well this seems to be all over the classes. I see about 89 instances where 89 instances seems doable. I probably could submit a PR by afternoon. |
Not sure to follow. The point of If I have understood correctly, what you've found is that: when a Python error is raised within a callback, libgit2 will return an error code and the original Python exception will be masked, while it should be re-raised. The subject of exceptions has been discussed before (though not the callback issue). See issue #830, which is a follow-up of two other issues. For reference I found as well issue #844, which I missed at the time 😕 One important thing is to keep backwards compatibility. For that purpose in issue #830 the proposal is to use multiple inheritance. Backwards compatibility can be broken when it makes sense, but hopefully not too much. Could you please be more specific on your proposal? Maybe after looking at the background discussion in issue #830 Thanks! |
And thanks for sponsoring! |
The PR I'm working on now should be fully backward compatible (actually, the new exception class I propose would inherit from I'm not looking into #844 explicitly for now since this seems to be libgit2 related but I'm confident that the proposed change will not make it any more difficult to fix then it is currently if anyone decides to fix it.
Sure thing! Thanks for the lib! I think most ppl. don't realize how bady we need automated Git for many common devops scenarios. |
Pushed a first version in https://github.com/m451/pygit2/commit/08ab93b114fe3a56200a136c490dc592a52c243e Didn't have time to test everything yet since it's getting late but I wanted to push it for the unittests to kick in. |
Some tests are still failing with https://github.com/m451/pygit2/commit/420cc9aa1b23c57bd8fb7cf9b47bf03340abdcd8 and I'm not sure why. Will have to digg into the tests. I believe the issue is that the unit tests have not been setup for exception handling yet. This is the list of tests that seem to be failing:
Quite hard for me to debug since I don't have a local build env but I'll see what I can do. |
No errors in the unit tests anymore and only actually needed to change one test to check the resulting error message more specificly for all to work, so it should be backwards compatible with any older code. https://github.com/m451/pygit2/commit/6d45967f4939ee97533c37dbb3c9e744a1cdf40a is a first implementation I came up with. However: getting rid of that Since this is more related to #830 I added a TODO list there and would suggest we continue the discussion there. I'll reference this issue in there as to be tested because since I wasn't able to fully get rid of the BTW: since I saw Python 3.5 was dropped, I decided to use f-Strings where possible. Hope that's fine. |
The issue reported here was fixed with commit cd09686, now in commit a92a453 I've added a unit test for it. Exceptions within a user defined callback are properly re-raised so they can be handled by the code calling the pygit2 API. Other places where we use callbacks were already good, they didn't suffer from this problem. There was already a unit test for fetch: |
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 genericGitError
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.
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 theerrors.py
module. However, the actual Exception stored in_stored_exception
is never processed there. Instead, it simply raises aGitError
with the messageerr -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:
and calls it like this:
One would expect the output to be:
While we actually get:
The text was updated successfully, but these errors were encountered: