Skip to content

Commit 86ce22c

Browse files
committed
process error as normal type
1 parent 92e5530 commit 86ce22c

14 files changed

Lines changed: 1022 additions & 871 deletions

File tree

zenoh-flat-jni/build.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,39 @@ fn main() {
2121
.handle_locks(true) // Enable handle locks (default, thread-safe)
2222
.source_module(pq!(zenoh_flat)) // how to prefix prebindgen-marked items (functions, types
2323
.package_prefix("io.zenoh.jni") // the package of the generated JNI bindings
24-
.data_class(pq!(Error)) // structured Kotlin data class for the Result error type
24+
// Error model: zenoh's native `ZError` is the `E` of every fallible
25+
// `Result<_, ZError>`. It never crosses as a value — a CONVERTER
26+
// (`z_error_message -> String`) marked `.default()` auto-applies a
27+
// `convert_error` to EVERY declared fn returning `Result<_, ZError>`, so
28+
// the generated wrapper's `onError` callback receives the error string as
29+
// its single `ze` param (after the fixed binding `je: String?`). No throw
30+
// from zenoh-flat-jni; the caller's `onError` decides (zenoh-java throws
31+
// `ZError`).
32+
.converter(pq!(ZError), pq!(z_error_message))
33+
.default()
34+
// `ZError` has no value-crossing of its own — but the rank-2
35+
// `Result<T, ZError>` resolver still requires an output converter for the
36+
// `E` position. Register the same `→ String` lowering so `Result` types
37+
// resolve; for fallible fns the error plan peels the `Result` in the
38+
// extern, so this converter is resolved-but-unused (the error reaches the
39+
// callback via `convert_error`). Harmless and semantically correct.
40+
.output_wrapper(pq!(ZError), |_: &Registry<_>| {
41+
Some((pq!(String), None, pq!(zenoh_flat::z_error_message(&v))))
42+
})
43+
// Symmetric input side: required by the resolver's propagation through
44+
// the fallible constructors' `Result<_, ZError>` signatures, but **never
45+
// actually crossed** (no fn takes `ZError` from the JVM). A terminal that
46+
// ignores the wire and yields a dummy `ZError` satisfies resolution; it is
47+
// dead code (no extern param has `ZError` input).
48+
.input_wrapper(pq!(ZError), |_: &Registry<_>| {
49+
Some((
50+
pq!(ZError),
51+
None,
52+
pq!(<zenoh_flat::ZError as ::core::convert::From<::std::string::String>>::from(
53+
::std::string::String::new()
54+
)),
55+
))
56+
})
2557
.package("keyexpr")
2658
.ptr_class(pq!(ZKeyExpr))
2759
.package_fun(pq!(z_keyexpr_try_from))

zenoh-flat-jni/generated-kotlin/io/zenoh/jni/Error.kt

Lines changed: 0 additions & 14 deletions
This file was deleted.

zenoh-flat-jni/generated-kotlin/io/zenoh/jni/NativeHandle.kt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,7 @@ internal inline fun <R> withSortedHandleLocks(
4949
return synchronized(x) { synchronized(y) { synchronized(z) { body() } } }
5050
}
5151

52-
/** Error callback invoked by native code instead of throwing. */
53-
public fun interface ErrorSink {
54-
public fun onError(message: String)
55-
}
56-
57-
/** Mutable holder a default [ErrorSink] writes into; the wrapper
58-
* rethrows after the native call returns. */
59-
public class ErrorHolder {
60-
@JvmField public var message: String? = null
61-
}
62-
63-
/** Exception a generated wrapper raises when native code reported an
64-
* error via the [ErrorSink] channel. */
65-
public class ZException(message: String?) : Exception(message)
52+
/** Default error raised by a generated wrapper's `onError` when the
53+
* caller doesn't supply a handler. `message` is the binding error
54+
* (`je`) or the library error string (`ze`). */
55+
public class ZException(message: String?) : RuntimeException(message)

0 commit comments

Comments
 (0)