Skip to content

Commit

Permalink
feature(tlua): show how many values were attempted to be pushed
Browse files Browse the repository at this point in the history
  • Loading branch information
gmoshkin committed Apr 1, 2022
1 parent db51234 commit 9c4b374
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion tarantool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ libc = "0.2"
log = "0.4"
num-traits = "0.2"
num-derive = "0.3"
tlua = { path = "../tlua", version = "0.6.0" }
tlua = { path = "../tlua", version = "0.7.0" }
protobuf = { version = "2", optional = true }
raft = { version = "0.6.0", optional = true }
refpool = { version = "0.4.3", optional = true }
Expand Down
6 changes: 3 additions & 3 deletions tests/src/tlua/rust_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,17 +776,17 @@ pub fn error_during_push_iter() {
let lua = {
let _guard = LuaStackIntegrityGuard::new("push_vec_too_many", &lua);
let (e, lua) = lua.try_push(vec![(1, 2, 3)]).unwrap_err();
assert_eq!(e, tlua::PushIterError::TooManyValues);
assert_eq!(e, tlua::PushIterError::TooManyValues(3));
assert_eq!(e.to_string(),
"Can only push 1 or 2 values as lua table item"
"Can only push 1 or 2 values as lua table item, got 3 instead"
);
lua
};

let lua = {
let _guard = LuaStackIntegrityGuard::new("push_iter_too_many", &lua);
let (e, lua) = lua.try_push_iter(std::iter::once((1, 2, 3))).unwrap_err();
assert_eq!(e, tlua::PushIterError::TooManyValues);
assert_eq!(e, tlua::PushIterError::TooManyValues(3));
lua
};

Expand Down
2 changes: 1 addition & 1 deletion tests/src/tlua/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ pub fn tuple_as_table() {
let (e, _) = (&lua).try_push(AsTable(((1, 2), (1, 2, 3)))).unwrap_err();
assert_eq!(
e.to_string(),
"Can only push 1 or 2 values as lua table item"
"Can only push 1 or 2 values as lua table item, got 3 instead"
);
}

2 changes: 1 addition & 1 deletion tlua/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tlua"
version = "0.6.1"
version = "0.7.0"
edition = "2018"
authors = [
"[email protected]",
Expand Down
15 changes: 8 additions & 7 deletions tlua/src/rust_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ where
// TODO(gmoshkin): return an error capturing this push guard
// n + 1 == n values from the recent push + lua table
drop(PushGuard::new(lua.as_lua(), n + 1));
return Err((PushIterError::TooManyValues, lua))
return Err((PushIterError::TooManyValues(n), lua))
}
}
}
Expand All @@ -67,7 +67,7 @@ pub type PushIterErrorOf<I> = PushIterError<<<I as Iterator>::Item as PushInto<L

#[derive(Debug, PartialEq, Eq)]
pub enum PushIterError<E> {
TooManyValues,
TooManyValues(i32),
ValuePushError(E),
}

Expand All @@ -78,7 +78,7 @@ impl<E> PushIterError<E> {
{
match self {
Self::ValuePushError(e) => PushIterError::ValuePushError(f(e)),
Self::TooManyValues => PushIterError::TooManyValues,
Self::TooManyValues(n) => PushIterError::TooManyValues(n),
}
}
}
Expand All @@ -89,9 +89,10 @@ where
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::TooManyValues => {
Self::TooManyValues(n) => {
write!(fmt,
"Can only push 1 or 2 values as lua table item",
"Can only push 1 or 2 values as lua table item, got {} instead",
n,
)
}
Self::ValuePushError(e) => {
Expand Down Expand Up @@ -407,7 +408,7 @@ macro_rules! push_hashmap_impl {
($self:expr, $lua:expr) => {
push_iter($lua, $self.into_iter())
.map_err(|(e, lua)| match e {
PushIterError::TooManyValues => unreachable!("K and V implement PushOne"),
PushIterError::TooManyValues(_) => unreachable!("K and V implement PushOne"),
PushIterError::ValuePushError(First(e)) => (First(e), lua),
PushIterError::ValuePushError(Other(e)) => (Other(e.first()), lua),
})
Expand Down Expand Up @@ -466,7 +467,7 @@ macro_rules! push_hashset_impl {
($self:expr, $lua:expr) => {
push_iter($lua, $self.into_iter().zip(iter::repeat(true)))
.map_err(|(e, lua)| match e {
PushIterError::TooManyValues => unreachable!("K implements PushOne"),
PushIterError::TooManyValues(_) => unreachable!("K implements PushOne"),
PushIterError::ValuePushError(First(e)) => (e, lua),
PushIterError::ValuePushError(Other(_)) => {
unreachable!("no way to create instance of Void")
Expand Down
2 changes: 1 addition & 1 deletion tlua/src/tuples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ where
}
n => unsafe {
drop(PushGuard::new(raw_lua, n));
return Err(PushIterError::TooManyValues);
return Err(PushIterError::TooManyValues(n));
}
}
Ok(())
Expand Down

0 comments on commit 9c4b374

Please sign in to comment.