Skip to content

Commit

Permalink
fix(template): add full typename to invalid argument error (#1226)
Browse files Browse the repository at this point in the history
Description
---
fix(template): add full typename to invalid argument error

Motivation and Context
---
Adding the type name to the error message makes it easier to determine
an issue with a transaction.
```
Panic! failed to decode argument at position 0 (tari_template_lib::models::amount::Amount) for  function 'please_pass_invalid_args':
```
How Has This Been Tested?
---
Updated exiting unit test

What process can a PR reviewer use to test or verify this change?
---
Pass an invalid argument into a template

Breaking Changes
---

- [x] None
- [ ] Requires data directory to be deleted
- [ ] Other - Please specify
  • Loading branch information
sdbondi authored Dec 24, 2024
1 parent 0f0496a commit 973f8a1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion dan_layer/engine/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ mod errors {
match result.finalize.result.full_reject().unwrap() {
RejectReason::ExecutionFailure(message) => {
assert!(message.starts_with(
"Panic! failed to decode argument at position 0 for function 'please_pass_invalid_args':"
"Panic! failed to decode argument at position 0 (tari_template_lib::models::amount::Amount) for \
function 'please_pass_invalid_args':"
),);
},
reason => panic!("Unexpected failure reason: {}", reason),
Expand Down
22 changes: 20 additions & 2 deletions dan_layer/template_abi/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod no_std {
extern crate alloc;

pub use alloc::{boxed, format, str, string, vec};
pub use core::{cmp, fmt, iter, mem, num, ops, ptr, slice, write, writeln};
pub use core::{any, cmp, fmt, iter, mem, num, ops, ptr, slice, write, writeln};

pub mod collections {
extern crate alloc;
Expand All @@ -41,7 +41,25 @@ pub use no_std::*;

#[cfg(feature = "std")]
mod rust_std {
pub use ::std::{boxed, cmp, fmt, format, io, iter, mem, num, ops, ptr, slice, str, string, vec, write, writeln};
pub use ::std::{
any,
boxed,
cmp,
fmt,
format,
io,
iter,
mem,
num,
ops,
ptr,
slice,
str,
string,
vec,
write,
writeln,
};

pub mod collections {
pub use ::std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/template_lib/src/template_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
//! Public types that are available to internal template code.
pub use tari_bor::{decode, decode_exact, encode_with_len, from_value, serde};
pub use tari_template_abi::{wrap_ptr, CallInfo};
pub use tari_template_abi::{rust, wrap_ptr, CallInfo};

pub use crate::{args::LogLevel, debug, engine, get_context as context, init_context, panic_hook::register_panic_hook};
2 changes: 1 addition & 1 deletion dan_layer/template_macros/src/template/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn get_function_block(template_ident: &Ident, ast: FunctionAst) -> Expr {
args.push(parse_quote! { #arg_ident });
stmts.push(parse_quote! {
let #arg_ident = from_value::<#type_path>(&call_info.args[#i])
.unwrap_or_else(|e| panic!("failed to decode argument at position {} for function '{}': {}", #i, #func_name, e));
.unwrap_or_else(|e| panic!("failed to decode argument at position {} ({}) for function '{}': {}", #i, rust::any::type_name::<#type_path>(), #func_name, e));
})
},
TypeAst::Tuple { type_tuple, .. } => {
Expand Down

0 comments on commit 973f8a1

Please sign in to comment.