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

Unwrap InvocationTargetException which are ResponseErrorException #809

Merged
merged 3 commits into from
Feb 29, 2024

Conversation

jonahgraham
Copy link
Contributor

@jonahgraham jonahgraham commented Feb 14, 2024

By wrapping ResponseErrorException with another layer in RuntimeException it means the unwrapping of the exception in RemoteEndpoint.DEFAULT_EXCEPTION_HANDLER doesn't work as expected and instead of getting the original ResponseError the other end gets the fallback ResponseError of type internal error.

This change includes updates to documentation to show that it is ok to throw ResponseErrorException (reverts #578). While it is also OK to return an exceptionally completed future, it is not needed to do that way and simply throwing is more straightforward.

There are new tests to cover the changed handling. Also tested is the previously documented way of handling exceptions (see tries == 1 case in testVersatility and testVersatilityResponseError

Fixes #802

Copy link
Contributor

@pisv pisv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonahgraham This looks like a nice improvement indeed, thank you! 👍

It seems that the documentation update in #578 needs to be reverted or amended now, either as part of this PR or a follow-up.

@jonahgraham
Copy link
Contributor Author

I updated docs and updated tests. New commit was used to update description of the PR

@jonahgraham jonahgraham marked this pull request as draft February 14, 2024 19:39
@jonahgraham
Copy link
Contributor Author

There is one todo thing left, hence turned to draft, the code change when it is delegate segments has no test coverage. Probably also worth adding to changelog.

By wrapping ResponseErrorException with another layer in
RuntimeException it means the unwrapping of the exception in
RemoteEndpoint.DEFAULT_EXCEPTION_HANDLER doesn't work as
expected and instead of getting the original ResponseError
the other end gets the fallback ResponseError of type
internal error.

This change includes updates to documentation to show that
it is ok to throw ResponseErrorException (reverts #578).
While it is also OK to return an exceptionally completed
future, it is not needed to do that way and simply throwing
is more straightforward.

There are new tests to cover the changed handling. Also tested
is the previously documented way of handling exceptions (see
`tries == 1` case in `testVersatility` and `testVersatilityResponseError`

Fixes #802

Also-by: Vladimir Piskarev <pisv@1c.ru>
This exception is thrown when the endpoint is created, not as a result of
a receiving a message. This is generally a coding error, so make this
exception the same as the other exceptions thrown by recursiveFindRpcMethods.

Included is adding additional tests to ensure coverage of some
previously missing uses cases.

Code cleanup done as part of #802
@jonahgraham
Copy link
Contributor Author

There is one todo thing left, hence turned to draft, the code change when it is delegate segments has no test coverage. Probably also worth adding to changelog.

Newest commit adds to the changelog. It also adds the code coverage as the find delegate's change I had done previously was incorrect.

@jonahgraham jonahgraham marked this pull request as ready for review February 20, 2024 21:17
Copy link

@ivy-cst ivy-cst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for the fix 👍

pisv added a commit that referenced this pull request Feb 28, 2024
@pisv
Copy link
Contributor

pisv commented Feb 28, 2024

The 'sneaky throws' change is ready for review: 4de6734 :-)

@pisv
Copy link
Contributor

pisv commented Feb 28, 2024

I have another approach in the works, which does not use sneaky throws. It is based on the fact that an Endpoint is not expected to throw a checked exception. Therefore, throwing a checked exception from an annotated jsonrpc method can (and should) be treated as a programming error, and can be signalled via an IllegalStateException in the GenericEndpoint. An inaccessible jsonrpc method (IllegalAccessException) can also be handled in a similar way. There is no need to use sneaky throws or a CompletionException in this case. Runtime exceptions or errors would just be re-thrown.

Checked exceptions should not be thrown from annotated jsonrpc methods.
Such exceptions can be treated as a programming error, and signaled via
an IllegalStateException in the GenericEndpoint.

An inaccessible jsonrpc method can be handled in a similar way.

For detailed discussion and context, see
#809 (comment).
@pisv
Copy link
Contributor

pisv commented Feb 29, 2024

The latest change is ready for review: 3982fd3.

Copy link
Contributor Author

@jonahgraham jonahgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Silly GitHub - I can't approve my own PR even though I am reviewing @pisv's latest change)

+1 on this change.

Copy link
Contributor

@pisv pisv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that @jonahgraham has approved my latest change, this PR is complete and ready to be merged, as far as I can tell.

Thank you @jonahgraham and @ivy-cst!

@jonahgraham jonahgraham merged commit c1d4cd3 into main Feb 29, 2024
8 checks passed
@jonahgraham jonahgraham deleted the jonah/response-error-lost branch February 29, 2024 14:18
@jonahgraham jonahgraham added this to the 0.23.0 milestone Feb 29, 2024
@jonahgraham
Copy link
Contributor Author

@ivy-cst this change should end up on snapshot builds soon: https://github.com/eclipse-lsp4j/lsp4j?tab=readme-ov-file#snapshots

Please comment in #807 if you have input on if/when a full release will help your adoption so that I can consider how and when to make a release.

@ivy-cst
Copy link

ivy-cst commented Mar 1, 2024

@ivy-cst this change should end up on snapshot builds soon: https://github.com/eclipse-lsp4j/lsp4j?tab=readme-ov-file#snapshots

Please comment in #807 if you have input on if/when a full release will help your adoption so that I can consider how and when to make a release.

Thank you for the fix. We do not need a release. We are currently living with our own exception handler. We are tied to the eclipse rcp releases at the moment anyway.

@jonahgraham
Copy link
Contributor Author

OK thanks for responding - if that changes please comment on #807

PS I really appreciate that you followed up on this issue, especially knowing that it did not affect your code in the short term. It will now make everyone's code in the future better and is part of what makes me very happy to be working on open source projects with a vibrant community!

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.

ResponseErrorException is not propagated with the default exception handler
3 participants