chore(napi): enhance error message when unwrap failed from JsObject (#1259)

This commit is contained in:
LongYinan 2022-08-07 23:05:49 +08:00 committed by GitHub
parent b8f96d517d
commit 4412c28c6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,4 @@
use std::any::TypeId; use std::any::{type_name, TypeId};
use std::convert::TryInto; use std::convert::TryInto;
use std::ffi::CString; use std::ffi::CString;
#[cfg(all(feature = "tokio_rt", feature = "napi4"))] #[cfg(all(feature = "tokio_rt", feature = "napi4"))]
@ -805,7 +805,10 @@ impl Env {
} else { } else {
Err(Error::new( Err(Error::new(
Status::InvalidArg, Status::InvalidArg,
"Invalid argument, T on unwrap is not the type of wrapped object".to_owned(), format!(
"Invalid argument, {} on unwrap is not the type of wrapped object",
type_name::<T>()
),
)) ))
} }
} }
@ -832,7 +835,10 @@ impl Env {
} else { } else {
Err(Error::new( Err(Error::new(
Status::InvalidArg, Status::InvalidArg,
"Invalid argument, T on unwrap is not the type of wrapped object".to_owned(), format!(
"Invalid argument, {} on unwrap is not the type of wrapped object",
type_name::<T>()
),
)) ))
} }
} }
@ -853,7 +859,10 @@ impl Env {
} else { } else {
Err(Error::new( Err(Error::new(
Status::InvalidArg, Status::InvalidArg,
"Invalid argument, T on unwrap is not the type of wrapped object".to_owned(), format!(
"Invalid argument, {} on unwrap is not the type of wrapped object",
type_name::<T>()
),
)) ))
} }
} }
@ -1172,7 +1181,10 @@ impl Env {
} else { } else {
Err(Error::new( Err(Error::new(
Status::InvalidArg, Status::InvalidArg,
"Invalid argument, T on unwrap is not the type of wrapped object".to_owned(), format!(
"Invalid argument, {} on unwrap is not the type of wrapped object",
type_name::<T>()
),
)) ))
} }
} }