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

SiriusResult should wrap Throwable (issue #8) #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

smuir
Copy link
Contributor

@smuir smuir commented Feb 13, 2014

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

There's no particular reason why SiriusResult can only wrap RuntimeException
as an error, so generalise it to Throwable (analogous to the Try class).
@comcast-jonm
Copy link
Member

There's another backwards-compatibility angle here, which is that old client code looking like this:

SiriusResult result = ...;
if (result.isError()) {
  try {
    result.getValue();
  except (RuntimeException re) {
    /* this catches everything that can be thrown here */
  }
}

May get a subtle surprise if a SiriusResult somehow shows up with a checked exception or an Error.

However, I am +1 on this being part of a revamped 1.2 interface, which I'll get around to adding shortly.

@smuir
Copy link
Contributor Author

smuir commented Feb 13, 2014

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

@smuir
Copy link
Contributor Author

smuir commented Feb 13, 2014

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.

@clinedome-work
Copy link
Collaborator

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.

@smuir
Copy link
Contributor Author

smuir commented Feb 13, 2014

Interesting question. I don't think the signature of getValue() is changed by changing the underlying type of the exception field.

@clinedome-work
Copy link
Collaborator

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.
@smuir
Copy link
Contributor Author

smuir commented Feb 13, 2014

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.
@smuir
Copy link
Contributor Author

smuir commented Feb 14, 2014

Just made a minor to change to make it possible to directly retrieve the Throwable associated with a SiriusResult.

@smuir
Copy link
Contributor Author

smuir commented Feb 15, 2014

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?

@comcast-jonm
Copy link
Member

This might need rebasing and resubmitting now that we're on a public TravisCI build.

@smuir
Copy link
Contributor Author

smuir commented Aug 8, 2014

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 RequestHandler (issue #6 )

@CLAassistant
Copy link

CLAassistant commented Jul 22, 2019

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Successfully merging this pull request may close these issues.

None yet

4 participants