Add last-error reporting to FFI (iOS + Android)#135
Open
AYastrebov wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
shoes_startreturns 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_ERRORglobal (OnceLock<parking_lot::Mutex<Option<String>>>) inffi/common.rsshared 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 viaCString::into_raw(), orNULLif no errorshoes_free_string(ptr)— the Swift wrapper always pairs these callsshoes_free_string()added for safe deallocationAndroid
ShoesNative.getLastError()returnsString?via JNIJString::null()if no error storedFiles changed
src/ffi/common.rsLAST_ERRORglobal +set/clear/get_last_error()+ testssrc/ffi/ios.rsshoes_get_last_error()+shoes_free_string()exportssrc/ffi/android.rsShoesNative.getLastError()JNI implementationsrc/ffi/mod.rscommonmodule in test buildsinclude/shoes.hshoes_get_last_error+shoes_free_stringShoesNative.ktgetLastError()external declarationTest plan
cargo test --lib --features ffi ffi::common— 3 unit tests pass (set/get, clear, overwrite)shoes_get_last_error()after a failed start, verify error string, free withshoes_free_string()ShoesNative.getLastError()after a failed start, verify non-null error string🤖 Generated with Claude Code