-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
WebSockets Next: investigate error handling #39186
Comments
Here are my thoughts: I propose the introduction of an
A web socket endpoint can define multiple @OnError
void onIOException(IOException e) { ... }
@OnError
void onWhateverException(WhateverException e) { ... } Each For comprehensive error handling,
Some errors are terminal, resulting in the termination of the web socket connection. For instance, an Furthermore, I propose the ability to define a "global" error handler using a CDI bean that implements WDYT? |
I agree, but with the following caveat:
Why not just allow users to do something like: public class GlobalErrorHandlers {
@OnError
public void onWhateverException(WhateverException e) {
}
} as we do in RESTEasy Reactive? The advantages for something like are:
|
Hm, does it mean that if an exception thrown is assignable to the method parameter then the callback method should be used? Also what exactly does ambiguous mean? Suppose that we have multiple error handlers that match the thrown exception. Should we use the first one matching and log an error message or?
Currently, we don't support error codes. Should we file a separate issue for this?
The only inconsistency here is that other |
Yes, that's one of the ways we it in RESTEasy Reactive (the other is to allow the user to specify the type in the annotation itself).
In RESTEasy Reactive they can be global (i.e. for all REST endpoints) or per-class |
Ok, I understand this concept. The question is what to do if multiple error handlers apply to the given type? Let's take a few steps back and enumerate the cases where a user-defined error handler can be used:
Now the other question is: should we create a specific exception for each type of problem or one exception with an error code? |
I am in favor of the former because users can then decide which ones to handle and if we make a good class hierachy they could handle them in any granulrity they like.
JAX-RS has this (fairly) simple rule:
|
Well, that does not solve multiple providers with the same type? 🤔 |
In that case the priority is taken into account. |
Hehe, and suddenly a simple rule is not simple anymore :D |
I faced similar problem in SmallRye Fault Tolerance (see here) and went with this simple rule:
Of course, I'm piggybacking on the (relatively complex) selection rules for fallback methods, so I don't have to care about most cases of ambiguity. If you have per-class and global exception handlers, it seems best to attempt selecting a per-class exception handler first and only if there's none, try to select a global one, using the same rule. Unfortunately, this rule doesn't really resolve all possible cases of ambiguity. For per-class error handlers, I can see:
For global error handlers, assuming the same
Also, it seems that certain error handlers may be able to fix the problem and resume normal operation ( So the error handlers in general need to be able to send replies on the connection. If that was possible using the same approach as It might be useful to distinguish application-level concerns from fatal concerns by different annotations ( |
Here's a draft PR: #39705
For now, we only "catch" encoding/decoding errors and runtime problems (i.e. anything thrown by |
You should have an exception handler on the WebSocket connection. No? |
Yes, there is an exception handler. Be careful as it's called on the event loop, which may not be what you want for the |
Yes, but for this one I was thinking of another annotation ( |
- introduce OnError annotation - add encoding/decoding exceptions - also support global error handlers - see quarkusio#39186
- introduce OnError annotation - add encoding/decoding exceptions - also support global error handlers - see quarkusio#39186
@cescoffier If a callback (e.g. |
- introduce OnError annotation - add encoding/decoding exceptions - also support global error handlers - see quarkusio#39186
- introduce OnError annotation - add encoding/decoding exceptions - also support global error handlers - see quarkusio#39186
- introduce OnError annotation - add encoding/decoding exceptions - also support global error handlers - see quarkusio#39186
Done #39763 |
@mkouba sorry for the late reply, but yes, for both uni and multi, if they emit a failure, we should call the error handler. |
@cescoffier no problem!
However, in the docs we currently state "When returning a Multi, Quarkus subscribes to the returned Multi automatically and writes the emitted items until completion, failure, or cancellation. Failure or cancellation terminates the connection.". It does not make sense to call the error handler in this case, or? Or maybe it does not make sense to close the connection unless it's a bi-directional stream? |
Hm, maybe it does not make sense to close the connection at all. I mean, even for |
I agree, it should not close the connection. |
- introduce OnError annotation - add encoding/decoding exceptions - also support global error handlers - see quarkusio#39186 (cherry picked from commit bce9f55)
This issue was resolved in the following pull requests: |
- introduce OnError annotation - add encoding/decoding exceptions - also support global error handlers - see quarkusio#39186
- introduce OnError annotation - add encoding/decoding exceptions - also support global error handlers - see quarkusio#39186 (cherry picked from commit bce9f55)
Description
We should provide a way for users to handle errors - perhaps in a similar way as JAX-RS / Jakarta REST
Implementation ideas
No response
The text was updated successfully, but these errors were encountered: