-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add handler for exception that occurs within run? #71
Comments
Been using Kotter just fine without this, not a 1.0 blocker. |
Unfortunately you cannot just wrap everything in a try/ catch since exceptions thrown in the run block are not propagated to the main thread. |
Yes, good point. I'll look at this again and implement it if it's not too tricky. |
So, looked into this a bit more. In my local development work, I actually got it so that the run block would propagate its exception to the main thread:
However, exceptions in the section do not work like this (and should not work, by design, more on that below):
The reason the section version does not work is because some renders happen asynchronously:
Renders are async so that unnecessary intermediate renders can be ignored. The above example may only rerender once or maybe three times, based on threading timing. So now, we have two blocks backed by their own threads - the section block (runs on a special render thread) and the run block (runs on a background thread). Maybe I'm wrong, but it seems really confusing that an exception in the In conclusion, I'm thinking the best solution is just to handle exceptions explicitly:
My thinking is, exception handling in Kotter blocks should be fairly rare, and being explicit makes it less confusing and more consistent. Leaving things as is, both blocks would swallow any unhandled exceptions they have. P.S. It's possible my wording in the original comment was confusing, when I said "A user can themselves wrap everything inside a try / catch block", but I meant "inside a try / catch block within the run block" |
Closing this issue for now, but feel free to leave more feedback / usecases I hadn't considered if you disagree. |
Ok, I understand your reasoning. And since it is easy to create an extension function to |
By the way, feel free to share some example code with me. I'd love to see your extension method if you write it and the project is public. It's definitely possible I'm just not seeing something because I'm too close to the code here. |
Yes sure. Find below a stripped version showcasing only the rethrowing. As I mentioned earlier I need all uncaught exception to bubble up in order to establish some centralized error output. To elaborate a bit: I am using Kotter in conjunction with Clikt to write some CLI tool. But not each and every command uses Kotter for its output, so handling exceptions at the top is the easiest way for me to have that said error output.
|
My code actually looks a bit different. I created a replacement extension function for This showed me how easily Kotter can be customized :-) |
Thanks for the context!
And are you not worried about exceptions that originate within sections?
I can definitely have exception propagation work in just run blocks, I just wasn't sure if that inconsistency would be confusing.
|
Awesome! I definitely made sure (with a few exceptions using the |
No. Unlike What I did though is to catch and render exceptions occurring in |
Also I didn't find a way from the "outside" to catch and propagate any exception in |
I'm thinking about using the coroutine library as an example and adding a run exception handler when you create a session, so maybe you can do something like this:
which would be backwards compatible and less confusing because you explicitly signed up for it. That said, it may just be easy enough to have Give me a bit more time to chew on it. I'll reopen this bug as I think about it. I'm more and more leaning to just having |
Yeah, this is not trivial, because the code in It's only when you call The only thing I can think of at the moment to report |
OK, good news. This conversation convinced me 1) that Before, I did something like this:
because in my mental model, I kept thinking about So the code will essentially get simplified to:
which has the same behavior as before but means any exceptions thrown will propagate back to you without any crazy tricks. Thanks for giving me the chance to think this through. I already have it working locally; I'll upload a fix soon. And then I'll see if it makes sense to update the Kotter version soon! |
Awesome! Thanks for taking the time to look into it. Really appreciated. |
By the way, 1.0.0-rc1 was just published, which contains this fix.
…On Sat, Oct 8, 2022, 4:45 AM Christoph Drießen ***@***.***> wrote:
Awesome! Thanks for taking the time to look into it. Really appreciated.
—
Reply to this email directly, view it on GitHub
<#71 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKNONASAHTI63GYY34CXG3DWCFNFBANCNFSM5JNUJ67A>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
Thanks again. I will give it an immediate shot tomorrow. |
Right now, if an exception occurs within run, the program just exits. A user can themselves wrap everything inside a try / catch block (within the run block), but it might be nice if we had a method,
onFailure
maybe, similar toonFinished
Edit: Added "within the run block" for clarity
The text was updated successfully, but these errors were encountered: