use napi::bindgen_prelude::*; #[napi] pub fn throw_error() -> Result<()> { Err(Error::new(Status::InvalidArg, "Manual Error".to_owned())) } #[napi(catch_unwind)] pub fn panic() { panic!("Don't panic"); } #[napi] pub fn receive_string(s: String) -> String { s } pub enum CustomError { NapiError(Error), Panic, } impl AsRef for CustomError { fn as_ref(&self) -> &str { match self { CustomError::Panic => "Panic", CustomError::NapiError(e) => e.status.as_ref(), } } } #[napi] pub fn custom_status_code() -> Result<(), CustomError> { Err(Error::new(CustomError::Panic, "don't panic")) } #[napi] pub async fn throw_async_error() -> Result<()> { Err(Error::new(Status::InvalidArg, "Async Error".to_owned())) }