Skip to content

Commit

Permalink
fix error msg for empty type (#478)
Browse files Browse the repository at this point in the history
* fix error msg for empty type

* fix
  • Loading branch information
chenyan-dfinity authored Oct 17, 2023
1 parent a8322be commit b233dbc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/candid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
6 changes: 5 additions & 1 deletion rust/candid/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,11 @@ impl<'de> Deserializer<'de> {
where
V: Visitor<'de>,
{
Err(Error::subtype("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<V::Value>
where
Expand Down
3 changes: 1 addition & 2 deletions rust/candid/src/types/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down

0 comments on commit b233dbc

Please sign in to comment.