Skip to content

Commit 3f65002

Browse files
authored
fix: register error callback in FFI CLI binary (#575)
* fix: register error callback in FFI CLI binary Without `on_error`, fatal errors from the background sync task were silently swallowed and the CLI would hang waiting for Ctrl+C. * fix: terminate process on fatal error in `on_error` callback Addresses CodeRabbit review comment on PR #575 #575 (comment)
1 parent 734b35f commit 3f65002

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

dash-spv-ffi/src/bin/ffi_cli.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,23 @@ extern "C" fn on_progress_update(progress: *const FFISyncProgress, _user_data: *
257257
println!();
258258
}
259259

260+
// ============================================================================
261+
// Error Callback
262+
// ============================================================================
263+
264+
extern "C" fn on_error(error: *const c_char, _user_data: *mut c_void) {
265+
let msg = if error.is_null() {
266+
"unknown error".to_string()
267+
} else {
268+
unsafe { std::ffi::CStr::from_ptr(error) }
269+
.to_str()
270+
.unwrap_or("invalid error string")
271+
.to_string()
272+
};
273+
eprintln!("[FATAL] {}", msg);
274+
std::process::exit(1);
275+
}
276+
260277
fn main() {
261278
let matches = Command::new("dash-spv-ffi")
262279
.about("Run SPV sync via FFI using event callbacks")
@@ -423,7 +440,7 @@ fn main() {
423440
user_data: ptr::null_mut(),
424441
},
425442
error: FFIClientErrorCallback {
426-
on_error: None,
443+
on_error: Some(on_error),
427444
user_data: ptr::null_mut(),
428445
},
429446
};

0 commit comments

Comments
 (0)