Skip to content

Commit

Permalink
expand fatal error list on the jvm based on rxjava
Browse files Browse the repository at this point in the history
  • Loading branch information
evant committed Dec 5, 2023
1 parent 9e0e6ef commit 379d50d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions assertk/src/commonMain/kotlin/assertk/failure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal object FailureContext {
}

fun fail(error: Throwable) {
if (error.isOutOfMemory()) throw error
if (error.isFatal()) throw error
failureRef.value.last().fail(error)
}
}
Expand Down Expand Up @@ -83,7 +83,7 @@ internal inline fun <F: Failure, T> F.run(f: F.() -> T): T {
try {
return f()
} catch (e: Throwable) {
if (e.isOutOfMemory()) {
if (e.isFatal()) {
throw e
}
otherException = e
Expand Down Expand Up @@ -189,7 +189,7 @@ fun notifyFailure(e: Throwable) {
}

@PublishedApi
internal expect inline fun Throwable.isOutOfMemory(): Boolean
internal expect inline fun Throwable.isFatal(): Boolean

internal expect inline fun failWithNotInStacktrace(error: Throwable): Nothing

2 changes: 1 addition & 1 deletion assertk/src/jsMain/kotlin/assertk/failure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ internal actual inline fun failWithNotInStacktrace(error: Throwable): Nothing {
}

@PublishedApi
internal actual inline fun Throwable.isOutOfMemory(): Boolean = false
internal actual inline fun Throwable.isFatal(): Boolean = false
8 changes: 5 additions & 3 deletions assertk/src/jvmMain/kotlin/assertk/failure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ package assertk

internal actual inline fun failWithNotInStacktrace(error: Throwable): Nothing {
val filtered = error.stackTrace
.dropWhile { it.className.startsWith("assertk") }
.toTypedArray()
.dropWhile { it.className.startsWith("assertk") }
.toTypedArray()
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UnsafeCast")
error.stackTrace = filtered
throw error
}

@PublishedApi
internal actual inline fun Throwable.isOutOfMemory(): Boolean = this is OutOfMemoryError
internal actual inline fun Throwable.isFatal(): Boolean =
// https://github.com/ReactiveX/RxJava/blob/6a44e5d0543a48f1c378dc833a155f3f71333bc2/src/main/java/io/reactivex/exceptions/Exceptions.java#L66
this is VirtualMachineError || this is ThreadDeath || this is LinkageError
2 changes: 1 addition & 1 deletion assertk/src/nativeMain/kotlin/assertk/failure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ internal actual inline fun failWithNotInStacktrace(error: Throwable): Nothing {
}

@PublishedApi
internal actual inline fun Throwable.isOutOfMemory(): Boolean = this is OutOfMemoryError
internal actual inline fun Throwable.isFatal(): Boolean = this is OutOfMemoryError
2 changes: 1 addition & 1 deletion assertk/src/wasmJsMain/kotlin/assertk/failure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ internal actual inline fun failWithNotInStacktrace(error: Throwable): Nothing {
}

@PublishedApi
internal actual inline fun Throwable.isOutOfMemory(): Boolean = false
internal actual inline fun Throwable.isFatal(): Boolean = false

0 comments on commit 379d50d

Please sign in to comment.