Skip to content

Propagate exception to wasm-js and js in propagateExceptionFinalResort #4472

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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

murfel
Copy link
Contributor

@murfel murfel commented Jul 7, 2025

Fixes #4451

@murfel murfel requested a review from dkhalanskyjb July 7, 2025 13:17
Copy link
Collaborator

@dkhalanskyjb dkhalanskyjb left a comment

Choose a reason for hiding this comment

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

Makes sense, thanks!

throw IllegalStateException("My ISE")
}
job.join()
delay(1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this needed? Please add a comment to the code.

}

@Test
fun testThrows() = runTest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd expect a more descriptive name, like testHandlingUncaughtExceptionsInNodeJs. Maybe even a documentation comment explaining what exactly we are checking here. Given how much JS code there is in this file, it's not trivial to figure out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like test name is too short to include a very specific descriptive name, so I've only added a comment. Do you want me to rename the test name anyway into the next best thing? (I assume with the goal of having a better name should this test fail.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, having a rough idea of what failed when you see the list of failed tests after introducing a change is the point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just that all the info is in the class name + path (for platform), and naming this accurately would be duplicating those. Had we had a dozen tests, we wouldn't be naming them so verbosely. I've done it anyways for now.

@murfel
Copy link
Contributor Author

murfel commented Jul 7, 2025

Idea's internal formatter (CMD+Option+L) wants to format all js("""...""") blocks like this:

js(
    """
    globalThis.originalListeners = process.listeners('uncaughtException');
    process.removeAllListeners('uncaughtException');
"""
)

Instead of the simpler this, which is also the way it is written in docs.

js("""
    globalThis.originalListeners = process.listeners('uncaughtException');
    process.removeAllListeners('uncaughtException');
""")

Should we override the formatter, locally or globally, for this particular function?

@dkhalanskyjb
Copy link
Collaborator

What the IDE does is not the style used in our style guide: https://kotlinlang.org/docs/coding-conventions.html#strings Worth filing a bug, but I'm not sure who is wrong: the IDE, the style guide, or both.

The important thing, though, is for a project to have a consistent style, the specifics don't matter that much. In kotlinx.coroutines, we don't yet have a style for """ (grepping """, I see all sorts of formatting), so if you have a preference, please feel free to declare it the official kotlinx.coroutines style for """ and apply it everywhere.

@murfel murfel requested a review from dkhalanskyjb July 8, 2025 07:43
Copy link
Collaborator

@dkhalanskyjb dkhalanskyjb left a comment

Choose a reason for hiding this comment

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

Well done, thank you! I only have some minor remarks, but otherwise, this is good to go.

}

@Test
fun testThrows() = runTest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, having a rough idea of what failed when you see the list of failed tests after introducing a change is the point.

throw IllegalStateException("My ISE")
}
job.join()
delay(1) // Let the exception be re-thrown and handled.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor: an extra space.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, double space before comment was intentional. I think I got it from Python.

I wish the IDE reformat action would point this out, too!

Fixed to single space.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No big deal, this is just not the style adopted in our library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we enforce it in automated checks?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm open to this (and preventing merging if the style is incorrect), but only if this check doesn't make the CI fail for intermediate commits. It would be annoying to push code just to test something, without ensuring the code is pretty, only to be met with a useless style check complaint. That said, it makes sense to have this check block merging.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that instead of making such a check part of the regular CI pipeline, or a pre-commit hook, it could also be implemented as a GH Action, (I'm not 100% sure about this part, but) that'll report all problems right into the PR.

*/
@Test
fun testThrows() = runTest {
addUncaughtExceptionHandler()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we want to remove it afterward. Given that it doesn't seem like uncaught exceptions do anything on Wasm/JS by default, maybe it doesn't matter. Still, avoiding test cross-contamination is worth it so that this doesn't bite us when we forget about this test completely.

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.

3 participants