From 694f761fd9a9cfb9542d73b83bf3518bbe7910e6 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Tue, 24 Jan 2023 16:32:40 +0800 Subject: [PATCH] fix(napi): throw fatal error if cast return value failed (#1450) --- crates/napi/src/threadsafe_function.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/napi/src/threadsafe_function.rs b/crates/napi/src/threadsafe_function.rs index 132dffe8..e41289fe 100644 --- a/crates/napi/src/threadsafe_function.rs +++ b/crates/napi/src/threadsafe_function.rs @@ -569,7 +569,19 @@ unsafe extern "C" fn call_js_cb( value: return_value, value_type: crate::ValueType::Unknown, })) { - unsafe { sys::napi_throw(raw_env, JsError::from(err).into_value(raw_env)) }; + let message = format!( + "Failed to convert return value in ThreadsafeFunction callback into Rust value: {}", + err + ); + let message_length = message.len(); + unsafe { + sys::napi_fatal_error( + "threadsafe_function.rs:573\0".as_ptr().cast(), + 26, + CString::new(message).unwrap().into_raw(), + message_length, + ) + }; } } status