Skip to content

Add last-error reporting to FFI (iOS + Android)#135

Open
AYastrebov wants to merge 1 commit into
cfal:masterfrom
AYastrebov:feat/error-callback-pr
Open

Add last-error reporting to FFI (iOS + Android)#135
AYastrebov wants to merge 1 commit into
cfal:masterfrom
AYastrebov:feat/error-callback-pr

Conversation

@AYastrebov
Copy link
Copy Markdown
Contributor

Problem

shoes_start returns immediately but errors happen asynchronously (config parsing failures, tunnel setup errors, runtime crashes). There was no way for the host app to retrieve the error message after the fact.

Solution

Add a LAST_ERROR global (OnceLock<parking_lot::Mutex<Option<String>>>) in ffi/common.rs shared by both platforms.

Lifecycle: clear on start → set on async failure → read by app.

iOS

  • shoes_get_last_error() returns a heap-allocated C string via CString::into_raw(), or NULL if no error
  • Caller must free with shoes_free_string(ptr) — the Swift wrapper always pairs these calls
  • shoes_free_string() added for safe deallocation

Android

  • ShoesNative.getLastError() returns String? via JNI
  • Returns JString::null() if no error stored

Files changed

File Change
src/ffi/common.rs LAST_ERROR global + set/clear/get_last_error() + tests
src/ffi/ios.rs shoes_get_last_error() + shoes_free_string() exports
src/ffi/android.rs ShoesNative.getLastError() JNI implementation
src/ffi/mod.rs Include common module in test builds
include/shoes.h C header with shoes_get_last_error + shoes_free_string
ShoesNative.kt Kotlin getLastError() external declaration

Test plan

  • cargo test --lib --features ffi ffi::common — 3 unit tests pass (set/get, clear, overwrite)
  • iOS: call shoes_get_last_error() after a failed start, verify error string, free with shoes_free_string()
  • Android: call ShoesNative.getLastError() after a failed start, verify non-null error string

🤖 Generated with Claude Code

Store the error message when start_from_config fails or the service
stops with an error. Clear it on each new start.

iOS: shoes_get_last_error() returns a heap-allocated C string (caller
must free with shoes_free_string()), or NULL if no error.

Android: ShoesNative.getLastError() returns String? via JNI.

Also include common module in test builds so the LAST_ERROR unit tests
can run on desktop, and add 3 tests covering set/get/clear/overwrite.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@AYastrebov AYastrebov marked this pull request as ready for review May 5, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant