fix(napi): throw fatal error if cast return value failed (#1450)

This commit is contained in:
LongYinan 2023-01-24 16:32:40 +08:00 committed by GitHub
parent c8352a1fb0
commit 694f761fd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -569,7 +569,19 @@ unsafe extern "C" fn call_js_cb<T: 'static, V: ToNapiValue, R, ES>(
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