-
Notifications
You must be signed in to change notification settings - Fork 49
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
SiriusResult should wrap Throwable (issue #8) #25
base: master
Are you sure you want to change the base?
Conversation
There's no particular reason why SiriusResult can only wrap RuntimeException as an error, so generalise it to Throwable (analogous to the Try class).
There's another backwards-compatibility angle here, which is that old client code looking like this:
May get a subtle surprise if a SiriusResult somehow shows up with a checked exception or an However, I am +1 on this being part of a revamped 1.2 interface, which I'll get around to adding shortly. |
For that to be an issue in practice it would require that somehow existing code managed to get a superclass of RuntimeException wrapped in a SiriusResult. Is that possible? A backwards-compatible solution might be to not change the error(RuntimeException) factory method, but add an alternative used to wrap Throwable |
Anyway, I think the 'better' solution, as discussed in email, is a different API that uses Scala native types rather than SiriusResult, at least for future clients. |
Hmm, if we did this, wouldn't the method signature of anything in Java that calls getValue() have to change? I imagined that would get inferred through, but I'm not entirely sure. Whether SiriusResult is the right answer or not, I'd say there's value in avoiding the nested Scala-native types, even if they do most succinctly describe what's happening. They're a total bear to work with in Java. All for looking at this stuff in more detail for 1.2 though. |
Interesting question. I don't think the signature of getValue() is changed by changing the underlying type of the exception field. |
Upon testing, it doesn't. :) |
For backwards compatibility purposes it's preferable to not change the signature of the error() method. So let's add an exception() method that allows wrapping of a Throwable in SiriusResult. That way, there is no danger of existing code somehow accidentally getting a Throwable where it expects a RuntimeException.
Updated to add an exception() method to wrap Throwable, with error() being reverted to the original interface of accepting only a RuntimeException |
Extend SiriusResult with a method to retrieve the associated Throwable without having to catch an exception.
Just made a minor to change to make it possible to directly retrieve the Throwable associated with a SiriusResult. |
The Travis CI build sometimes seems to fail for one of the two versions of Scala compiler, but not the other. Anyone got any ideas why? |
This might need rebasing and resubmitting now that we're on a public TravisCI build. |
If we are going to consider a new 1.3 release that has a more standard return type than SiriusResult, a la #26, then this might not be worth bothering with. But it seems like #26 was generally decided against, in which case this could easily be respun if it was thought to be useful. It probably isn't actually useful until we get to the point that return values actually propagate from the |
|
There's no particular reason why SiriusResult can only wrap RuntimeException as an error, so generalise it to Throwable (analogous to the Scala Try class).
See #8