Skip to content

Commit 52a86ec

Browse files
sagpatilfnando
andauthored
Improve CLI error handling for contract invocation arguments (#2235)
Fixes #2182 - Enhanced error messages with context and suggestions for better developer experience when invoking contracts, especially with bash scripts. Providing detailed, context-rich error messages for contract invocation arguments, including expected vs. received types and actionable suggestions. - Pre-validating JSON arguments to catch malformed input and type mismatches early. - Detecting common mistakes, such as invalid addresses and quoting errors, with documentation links and best practices. - Refactoring argument parsing internals for better organization, maintainability, and adherence to Rust best practices: - Extracts long functions into focused helpers (build_clap_command, parse_command_matches, get_function_spec, parse_function_arguments, parse_single_argument, parse_file_argument, build_invoke_contract_args). - Improves error handling (e.g., replacing map().unwrap_or_else() with explicit matching). ### Example improvement: **Before**: Error: parsing argument amount: InvalidValue(Some(U64)) **After**: Failed to parse argument 'amount' - Expected u64 but received '"100"' Suggestion: For numbers, ensure no quotes around the value --------- Co-authored-by: Nando Vieira <me@fnando.com>
1 parent 8508cce commit 52a86ec

File tree

2 files changed

+511
-76
lines changed

2 files changed

+511
-76
lines changed

cmd/crates/soroban-test/tests/it/help.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async fn complex_enum_help() {
6262
async fn multi_arg_failure() {
6363
assert!(matches!(
6464
invoke_custom("multi_args", "--b").await.unwrap_err(),
65-
contract::invoke::Error::ArgParsing(arg_parsing::Error::MissingArgument(_))
65+
contract::invoke::Error::ArgParsing(arg_parsing::Error::MissingArgument { .. })
6666
));
6767
}
6868

0 commit comments

Comments
 (0)