From 4412c28c6d628553a400d9181d11e8e4efcebe2c Mon Sep 17 00:00:00 2001 From: LongYinan Date: Sun, 7 Aug 2022 23:05:49 +0800 Subject: [PATCH] chore(napi): enhance error message when unwrap failed from JsObject (#1259) --- crates/napi/src/env.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/napi/src/env.rs b/crates/napi/src/env.rs index 1c8a38cb..e9294e28 100644 --- a/crates/napi/src/env.rs +++ b/crates/napi/src/env.rs @@ -1,4 +1,4 @@ -use std::any::TypeId; +use std::any::{type_name, TypeId}; use std::convert::TryInto; use std::ffi::CString; #[cfg(all(feature = "tokio_rt", feature = "napi4"))] @@ -805,7 +805,10 @@ impl Env { } else { Err(Error::new( 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::() + ), )) } } @@ -832,7 +835,10 @@ impl Env { } else { Err(Error::new( 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::() + ), )) } } @@ -853,7 +859,10 @@ impl Env { } else { Err(Error::new( 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::() + ), )) } } @@ -1172,7 +1181,10 @@ impl Env { } else { Err(Error::new( 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::() + ), )) } }