From 0d4e122f28715a81d17bcbb72a192e97224fe1ab Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Mon, 16 Oct 2023 18:13:37 -0700 Subject: [PATCH 1/2] fix error msg for empty type --- Cargo.lock | 2 +- rust/candid/Cargo.toml | 2 +- rust/candid/src/de.rs | 2 +- rust/candid/src/types/value.rs | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d0334fe3..6ed7a8b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -257,7 +257,7 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "candid" -version = "0.9.9" +version = "0.9.10" dependencies = [ "anyhow", "arbitrary", diff --git a/rust/candid/Cargo.toml b/rust/candid/Cargo.toml index cd1aa777..5351fcbf 100644 --- a/rust/candid/Cargo.toml +++ b/rust/candid/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "candid" -version = "0.9.9" +version = "0.9.10" edition = "2021" authors = ["DFINITY Team"] description = "Candid is an interface description language (IDL) for interacting with canisters running on the Internet Computer." diff --git a/rust/candid/src/de.rs b/rust/candid/src/de.rs index 3e8404fe..ab7bb70f 100644 --- a/rust/candid/src/de.rs +++ b/rust/candid/src/de.rs @@ -423,7 +423,7 @@ impl<'de> Deserializer<'de> { where V: Visitor<'de>, { - Err(Error::subtype("Cannot decode empty type")) + Err(Error::msg("Cannot decode empty type")) } fn deserialize_future<'a, V>(&'a mut self, visitor: V) -> Result where diff --git a/rust/candid/src/types/value.rs b/rust/candid/src/types/value.rs index 89ac3cf5..a2676218 100644 --- a/rust/candid/src/types/value.rs +++ b/rust/candid/src/types/value.rs @@ -451,8 +451,7 @@ impl<'de> Visitor<'de> for IDLValueVisitor { 5u8 => { use std::io::Read; let len = leb128::read::unsigned(&mut bytes).map_err(E::custom)? as usize; - let mut buf = Vec::new(); - buf.resize(len, 0); + let mut buf = vec![0; len]; bytes.read_exact(&mut buf).map_err(E::custom)?; let meth = String::from_utf8(buf).map_err(E::custom)?; let id = crate::Principal::try_from(bytes).map_err(E::custom)?; From 7268f39e6a6a7379ee2ac0d6260892c19f5e83a7 Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Mon, 16 Oct 2023 19:40:10 -0700 Subject: [PATCH 2/2] fix --- rust/candid/src/de.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rust/candid/src/de.rs b/rust/candid/src/de.rs index ab7bb70f..036440c6 100644 --- a/rust/candid/src/de.rs +++ b/rust/candid/src/de.rs @@ -423,7 +423,11 @@ impl<'de> Deserializer<'de> { where V: Visitor<'de>, { - Err(Error::msg("Cannot decode empty type")) + Err(if *self.wire_type == TypeInner::Empty { + Error::msg("Cannot decode empty type") + } else { + Error::subtype("Cannot decode empty type") + }) } fn deserialize_future<'a, V>(&'a mut self, visitor: V) -> Result where