Skip to content
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

More consistent exceptions #146

Closed
Barteks2x opened this issue Feb 9, 2017 · 5 comments
Closed

More consistent exceptions #146

Barteks2x opened this issue Feb 9, 2017 · 5 comments

Comments

@Barteks2x
Copy link

Sometimes it's jgit RepositoryNotFoundException, sometimes it's GrgitException and now I discovered IllegalArgumentException. Any way to have single exception I can catch instead?

@ajoberstar
Copy link
Owner

At the moment, no, it will differ based on the situation.

Some of this is due to a couple changes in JGit, but more consistency in exceptions is warranted. I think I'd target this as a 2.0 improvement since it could be breaking to some people.

@ajoberstar ajoberstar added this to the 2.0.0 milestone Feb 13, 2017
@ajoberstar ajoberstar changed the title grgit throws different exceptions when git repository isn't found depending on context More consistent exceptions Feb 13, 2017
@ajoberstar
Copy link
Owner

Another note on this is that the "context", I add in some places actually covers up a more useful message in the cause exception. Might be better off just wrapping the exception and not providing my own message.

ajoberstar added a commit that referenced this issue Jul 30, 2017
Since JGit's exceptions are more information, all uses of custom
exception types were removed and JGit's are allowed to bubble up, when
there isn't any explicit handling needed.

This is not quite what the original requester in #146 had in mind, but this
seems like a better experience when something fails. For someone trying
to catch excpetions, they'll probably need to catch raw Exception. It
was unlikely trying to wrap them all was going to be successful anyway.
@ajoberstar
Copy link
Owner

I realize this is kind of the opposite of what you were looking for but, for 2.0 I've decided to stop having a GrgitException at all. In practice, this means JGit's exception types will bubble up, which are more informative anyway. This does make your situation worse though, since you could get any number of exception types. If you do have a situation where you need to catch everything, you'll need to go all the way to catch Exception.

@Barteks2x
Copy link
Author

Which is close to what I've been already doing. Right now I'm catching RuntimeException and not Exception, because nothing in these seems to throw any checked exceptions (and this is one of the cases where checked exception would be nicer).

@ajoberstar
Copy link
Owner

Groovy doesn't distinguish between checked/unchecked, so it should work out the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants