Background
The UniFFI/WASM FFI boundary in shared/src/ffi.rs currently uses
panic! to handle deserialization and serialization errors. Panicking
across an FFI boundary causes the host process (Swift/JS) to hard-crash
with no opportunity for error recovery.
What to change
Refactor the FFI methods to return Result<Vec<u8>, SomeError> instead
of panicking. UniFFI has native support for Result-returning functions,
so this should be straightforward to wire up on both the Rust and Swift
sides.
Scope
- Define an appropriate error type (or reuse one from
crux_core)
- Update FFI method signatures in
shared/src/ffi.rs
- Update the Swift
core.swift glue to handle the returned Result
- Add tests covering the error path
References
Background
The UniFFI/WASM FFI boundary in
shared/src/ffi.rscurrently usespanic!to handle deserialization and serialization errors. Panickingacross an FFI boundary causes the host process (Swift/JS) to hard-crash
with no opportunity for error recovery.
What to change
Refactor the FFI methods to return
Result<Vec<u8>, SomeError>insteadof panicking. UniFFI has native support for
Result-returning functions,so this should be straightforward to wire up on both the Rust and Swift
sides.
Scope
crux_core)shared/src/ffi.rscore.swiftglue to handle the returnedResultReferences
Resultsupport: https://mozilla.github.io/uniffi-rs/udl/errors.html