Throw via N-API if callback implementation returns an `Err`
@@ -144,6 +144,7 @@ macro_rules! callback {
{
use std::io::Write;
use ::std::mem;
+ use ::std::os::raw::c_char;
use ::std::ptr;
use $crate::sys;
use $crate::{Env, Status, Value, Any};
@@ -181,6 +182,14 @@ macro_rules! callback {
Ok(None) => env.get_undefined().into_raw(),
Err(e) => {
let _ = writeln!(::std::io::stderr(), "Error calling function: {:?}", e);
+ let message = format!("{:?}", e);
+ unsafe {
+ $crate::sys::napi_throw_error(
+ raw_env,
+ ptr::null(),
+ message.as_ptr() as *const c_char
+ );
+ }
env.get_undefined().into_raw()
}
}
