summaryrefslogtreecommitdiff
path: root/serde_v8/de.rs
diff options
context:
space:
mode:
authorYiyu Lin <linyiyu1992@gmail.com>2023-04-13 08:03:56 +0800
committerGitHub <noreply@github.com>2023-04-13 02:03:56 +0200
commit19c3e4f6dc31fd78e2793d0596d6a9cc3a30580a (patch)
tree1a761ee3b96c20f5c362f7ecfe15724484b36062 /serde_v8/de.rs
parente2853a955cf532491b4a4fbef669965cc2b44afe (diff)
refactor(serde_v8): move to `thiserror`, better error output (#18202)
Ref #17318 --------- Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'serde_v8/de.rs')
-rw-r--r--serde_v8/de.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/serde_v8/de.rs b/serde_v8/de.rs
index 5293a705d..d593ffbc5 100644
--- a/serde_v8/de.rs
+++ b/serde_v8/de.rs
@@ -281,8 +281,9 @@ impl<'de, 'a, 'b, 's, 'x> de::Deserializer<'de>
if obj.is_array() {
// If the obj is an array fail if it's length differs from the tuple length
let array = v8::Local::<v8::Array>::try_from(self.input).unwrap();
- if array.length() as usize != len {
- return Err(Error::LengthMismatch);
+ let array_len = array.length() as usize;
+ if array_len != len {
+ return Err(Error::LengthMismatch(array_len, len));
}
}
visitor.visit_seq(SeqAccess::new(obj, self.scope, 0..len as u32))
@@ -409,8 +410,9 @@ impl<'de, 'a, 'b, 's, 'x> de::Deserializer<'de>
let prop_names =
obj.get_own_property_names(self.scope, Default::default());
let prop_names = prop_names.ok_or(Error::ExpectedEnum)?;
- if prop_names.length() != 1 {
- return Err(Error::LengthMismatch);
+ let prop_names_len = prop_names.length();
+ if prop_names_len != 1 {
+ return Err(Error::LengthMismatch(prop_names_len as usize, 1));
}
prop_names.get_index(self.scope, 0).unwrap()
};