mirror of
https://github.com/mamoe/mirai.git
synced 2025-04-25 04:50:26 +08:00
Implement Throwable.unwrap
accordingly to the target platform. Fix #1404
This commit is contained in:
parent
3a9889b8c0
commit
2929db7f38
mirai-core-utils/src
@ -21,4 +21,16 @@ public actual fun ByteArray.encodeBase64(): String {
|
||||
|
||||
public actual fun String.decodeBase64(): ByteArray {
|
||||
return Base64.decode(this, Base64.DEFAULT)
|
||||
}
|
||||
}
|
||||
|
||||
public actual inline fun <reified E> Throwable.unwrap(): Throwable {
|
||||
if (this !is E) return this
|
||||
if (suppressed.isNotEmpty()) return this
|
||||
val e =
|
||||
Exception("unwrapped exception: $this").also { // Android JDK could not resolve circular references so we copy one.
|
||||
it.stackTrace = this.stackTrace
|
||||
}
|
||||
return this.findCause { it !is E }
|
||||
?.also { it.addSuppressed(e) }
|
||||
?: this
|
||||
}
|
||||
|
@ -157,13 +157,7 @@ public fun Throwable.unwrapCancellationException(): Throwable = unwrap<Cancellat
|
||||
* at net.mamoe.mirai.internal.network.impl.netty.NettyNetworkHandler.close(NettyNetworkHandler.kt:404)
|
||||
* ```
|
||||
*/
|
||||
|
||||
public inline fun <reified E> Throwable.unwrap(): Throwable {
|
||||
if (this !is E) return this
|
||||
if (suppressed.isNotEmpty()) return this
|
||||
return this.findCause { it !is E }
|
||||
?.also { it.addSuppressed(this) }
|
||||
?: this
|
||||
}
|
||||
@Suppress("unused")
|
||||
public expect inline fun <reified E> Throwable.unwrap(): Throwable
|
||||
|
||||
public val CoroutineContext.coroutineName: String get() = this[CoroutineName]?.name ?: "unnamed"
|
@ -21,4 +21,12 @@ public actual fun ByteArray.encodeBase64(): String {
|
||||
|
||||
public actual fun String.decodeBase64(): ByteArray {
|
||||
return Base64.getDecoder().decode(this)
|
||||
}
|
||||
}
|
||||
|
||||
public actual inline fun <reified E> Throwable.unwrap(): Throwable {
|
||||
if (this !is E) return this
|
||||
if (suppressed.isNotEmpty()) return this
|
||||
return this.findCause { it !is E }
|
||||
?.also { it.addSuppressed(this) }
|
||||
?: this
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user