Skip to content

Commit 842977c

Browse files
fliskybendk
authored andcommitted
kotlin: use Throwable.stackTraceToString to show more info
1 parent 51dbbed commit 842977c

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

fixtures/callbacks/tests/bindings/test_callbacks.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ try {
102102
throw RuntimeException("Expected ComplexException.UnexpectedErrorWithReason")
103103
} catch (e: ComplexException.UnexpectedErrorWithReason) {
104104
// Expected error
105-
assert(e.reason == RuntimeException("something failed").toString())
105+
assert(e.reason.startsWith(RuntimeException("something failed").toString()))
106106
}
107107

108108

uniffi_bindgen/src/bindings/kotlin/templates/Helpers.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ internal inline fun<T> uniffiTraitInterfaceCall(
102102
try {
103103
writeReturn(makeCall())
104104
} catch(e: kotlin.Exception) {
105+
val err = try { e.stackTraceToString() } catch(_: Throwable) { "" }
105106
callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
106-
callStatus.error_buf = {{ Type::String.borrow()|lower_fn }}(e.toString())
107+
callStatus.error_buf = {{ Type::String.borrow()|lower_fn }}(err)
107108
}
108109
}
109110

@@ -120,8 +121,9 @@ internal inline fun<T, reified E: Throwable> uniffiTraitInterfaceCallWithError(
120121
callStatus.code = UNIFFI_CALL_ERROR
121122
callStatus.error_buf = lowerError(e)
122123
} else {
124+
val err = try { e.stackTraceToString() } catch(_: Throwable) { "" }
123125
callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
124-
callStatus.error_buf = {{ Type::String.borrow()|lower_fn }}(e.toString())
126+
callStatus.error_buf = {{ Type::String.borrow()|lower_fn }}(err)
125127
}
126128
}
127129
}

0 commit comments

Comments
 (0)