From aadace83e6fc5dee79f015a60af773b86bcc6555 Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 14 Sep 2026 08:20:04 +0000 Subject: [PATCH] fix(android): return an error object from getBuckets instead of panicking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the datastore worker is gone (it panicked, e.g. the database could not be opened), get_buckets() fails with SendError/RecvError and the unwrap here panicked across the JNI boundary on the calling thread — usually the main thread. Observed while reproducing ActivityWatch/aw-android#261. Every other JNI entry point already returns create_error_object; the Kotlin callers of getBuckets tolerate a non-bucket JSON object. --- aw-server/src/android/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/aw-server/src/android/mod.rs b/aw-server/src/android/mod.rs index 09aeb554..7658ce9b 100644 --- a/aw-server/src/android/mod.rs +++ b/aw-server/src/android/mod.rs @@ -195,8 +195,14 @@ pub mod android { env: JNIEnv, _: JClass, ) -> jstring { - let buckets = openDatastore().get_buckets().unwrap(); - string_to_jstring(&env, json!(buckets).to_string()) + // Return an error object instead of unwrapping: if the datastore worker + // is gone (it panicked, e.g. the database could not be opened), the + // request fails with SendError/RecvError and a panic here unwinds across + // the JNI boundary on whatever thread called getBuckets — usually main. + match openDatastore().get_buckets() { + Ok(buckets) => string_to_jstring(&env, json!(buckets).to_string()), + Err(e) => create_error_object(&env, format!("Failed to get buckets: {e:?}")), + } } #[no_mangle]