-
Notifications
You must be signed in to change notification settings - Fork 1.9k
propagateExceptionFinalResort-nodejs-reportError #4511
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
base: develop
Are you sure you want to change the base?
Changes from all commits
4ba989a
4feef8e
cffc36b
1fc5783
824b8a4
9931acd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# Change log for kotlinx.coroutines | ||
|
||
## Version 1.10.3 | ||
* Unhandled exceptions in Kotlin coroutines are now re-thrown into the environment instead of being logged into the console on the `js` and `wasmJS` targets. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be annotated as Breaking changes / Behavior change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We only update changelogs as part of the release procedure: https://github.com/Kotlin/kotlinx.coroutines/blob/master/RELEASE.md This way, several changes can be combined and described in bulk or undo one another. |
||
|
||
## Version 1.10.2 | ||
|
||
* Fixed the `kotlinx-coroutines-debug` JAR file including the `module-info.class` file twice, resulting in failures in various tooling (#4314). Thanks, @RyuNen344! | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ package kotlinx.coroutines.internal | |
|
||
internal actual typealias JsAny = kotlin.js.JsAny | ||
|
||
internal external object globalThis : JsAny { | ||
val reportError: ((error: JsAny) -> Unit)? | ||
} | ||
|
||
internal actual fun Throwable.toJsException(): JsAny = | ||
toJsError(message, this::class.simpleName, stackTraceToString()) | ||
|
||
|
@@ -14,3 +18,15 @@ internal fun toJsError(message: String?, className: String?, stack: String?): Js | |
return error; | ||
""") | ||
} | ||
|
||
internal actual fun propagateExceptionFinalResort(exception: Throwable) { | ||
val jsException = exception.toJsException() | ||
// https://github.com/JetBrains/kotlin-wrappers/blob/master/kotlin-browser/src/webMain/generated/web/errors/reportError.kt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using commit hashes instead of branch names can make such links more reliable. I wanted to say "this link could start returning 404 tomorrow", but in fact, it returns 404 for me today! |
||
if (globalThis.reportError != null) { | ||
// Modern browsers, Deno, Bun, etc. | ||
globalThis.reportError(jsException) | ||
Comment on lines
+24
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I understand, we can only rely on |
||
} else { | ||
// Old Safari, Node.js | ||
throwAsync(jsException) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think mentioning that it still only prints to console in browser is not needed, since it, in fact, now throws in browser, only the browser chooses to log it into console.
Also, the logged exception message in browser may change, as it will now be formatted by the browser's preference, rather than by us.