pygit2
pygit2 copied to clipboard
Review exceptions
To have one exception for every GIT_EXXX all of them inheriting from GitError, use a consistent naming, e.g. GIT_EINVALIDSPEC would become GitInvalidSpecError or maybe just InvalidSpecError.
To provide backwards compatibility use multiple inheritance, e.g. InvalidSpecError would inherit from GitError and ValueError. Eventually the base class for backwards compatibility would be remove in some future version.
To settle on naming post here the full mapping of GIT_EXXX to exception, even if this can be implemented in steps.
This follows up on issues #531 and #828
Sounds good to me.
Eventually the base class for backwards compatibility would be remove in some future version.
There's some precedent in Python's standard library for exceptions with multiple base classes, see this post:
https://www.reddit.com/r/Python/comments/1k9ygb/multiple_inheritance_for_library_exceptions/
So maybe it's not necessarily a bad thing that needs to be removed in the future.
yes you're right, it may be a good thing
While I implemented a first version there are currently some reasons that stop us from fully switching to such a system that will probably need to be tackled one-by-one.
- [ ]
Passthroughneeds to be changed toGitPassthroughErrorto be consistent in the naming. The issue is that while I replaced all instances in PyGit2 with the new name,Passthroughmight be used by users. I therefor letGitPassthroughErrorinherit fromPassthroughand didn't deletePassthroughyet. So,Passthroughcan be viewed as deprecated and some time in future should be removed. Also since I'm not sure what side effectsPassthroughhas on the flow logic (it is a special error, just likeGIT_EUSER) I didn't yet add it to the automatic error generation, it still has to be explicitly raised by some Python code. - [ ]
GIT_EUSERis currently used to control the flow of some wrappers. It seems the current logic that usesGIT_EUSERreturn codes needs to be changed in a way that it's using the newGitUserErrorexception. This seems to be quite hard as I yet don't fully understand the flow logic there. Some help with this would be awesome. - [ ] Because of that mentioned
GIT_EUSER(and the related_stored_exceptionlogic) issue and the fact that some exceptions are currently catched and never raise it's not clear if #996 is fixed with this implementation or if theGIT_EUSERthing first needs to be fixed/replaced. The functions of interest seem to be_fill_fetch_options,_fill_push_options,_fill_prune_callbacks,_fill_connect_callbacksand all callers of those as well as the@ffi.callbackwrapper. - [ ] The old exception handling used
check_error(err, io=False)and setio=Trueif it wanted aValueErrorto become aIOError. I'm not sure what was the reason for that but to be backwards compatible I kept it that way. Every line that previously made a call tocheck_error()withio=Truewas replaced by a special, temporary exception classGitIOError. You can find the relevant parts if you search forGitIOError.check_result(. Those parts need to be changed in a way that the actualGIT_Eerror is thrown and thenGitIOErrorcan be removed. Since I'm not sure what's the reason behind the explicit raise ofIOErrorinstead of other exceptions (e.g.ValueError) in first place this would need some clearification first. - [ ] So far I only implemented the
GIT_E*codes (and their matching classes) for the errors that are currently explicitly handled. Before all the remaining codes are implemented it would probably be a good idea to discuss what C calls currently occurre and what errors they could raise, and then add the new handling logic to them as needed. I marked the not yet implementedGIT_E*variants with aTODOin errors.py.