-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install a global uncaught exception handler (#1735)
* Install a global uncaught exception handler * Reference a coroutines feature request Kotlin/kotlinx.coroutines#3978
- Loading branch information
1 parent
f275f2a
commit 5815ba4
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...od-treehouse-guest/src/commonMain/kotlin/app/cash/redwood/treehouse/PrepareEnvironment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (C) 2023 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.redwood.treehouse | ||
|
||
import kotlinx.coroutines.CoroutineExceptionHandler | ||
|
||
/** | ||
* Customize the runtime for this Treehouse application. | ||
*/ | ||
internal expect fun prepareEnvironment( | ||
coroutineExceptionHandler: CoroutineExceptionHandler, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
redwood-treehouse-guest/src/jsMain/kotlin/app/cash/redwood/treehouse/PrepareEnvironmentJs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2023 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.redwood.treehouse | ||
|
||
import kotlin.coroutines.CoroutineContext | ||
import kotlinx.coroutines.CoroutineExceptionHandler | ||
|
||
/** | ||
* This installs a global coroutine exception handler using an internal API. | ||
* | ||
* This is necessary for uncaught exceptions to be delivered to the host application. Otherwise | ||
* they're logged to the console where they're easily missed. | ||
* | ||
* This assumes we're the [StandardAppLifecycle] owns the entire JS runtime. | ||
*/ | ||
@Suppress("INVISIBLE_MEMBER") // https://github.com/Kotlin/kotlinx.coroutines/issues/3978 | ||
internal actual fun prepareEnvironment( | ||
coroutineExceptionHandler: CoroutineExceptionHandler, | ||
) { | ||
kotlinx.coroutines.internal.ensurePlatformExceptionHandlerLoaded( | ||
object : CoroutineExceptionHandler by coroutineExceptionHandler { | ||
override fun handleException(context: CoroutineContext, exception: Throwable) { | ||
coroutineExceptionHandler.handleException(context, exception) | ||
throw kotlinx.coroutines.internal.ExceptionSuccessfullyProcessed | ||
} | ||
}, | ||
) | ||
} |
24 changes: 24 additions & 0 deletions
24
...reehouse-guest/src/nonJsMain/kotlin/app/cash/redwood/treehouse/PrepareEnvironmentNonJs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (C) 2023 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.redwood.treehouse | ||
|
||
import kotlinx.coroutines.CoroutineExceptionHandler | ||
|
||
internal actual fun prepareEnvironment( | ||
coroutineExceptionHandler: CoroutineExceptionHandler, | ||
) { | ||
// Do nothing. | ||
} |