Skip to content

commands: clear error for malformed decimal CLI arguments - #11006

Open
devdavidejesus wants to merge 1 commit into
spesmilo:masterfrom
devdavidejesus:cli-decimal-args
Open

devdavidejesus wants to merge 1 commit into
spesmilo:masterfrom
devdavidejesus:cli-decimal-args

Conversation

@devdavidejesus

Copy link
Copy Markdown

Fixes #7404.

Command-line arguments typed as decimal (decimal, decimal_or_dryrun, decimal_or_max in arg_types) were converted with lambdas that raise decimal.InvalidOperation on malformed input. argparse only turns ArgumentTypeError, TypeError and ValueError from a type function into a usage error, so any malformed amount crashed with a traceback. This affects every command with a decimal argument, not only add_request (e.g. payto <address> abc).

The conversion now goes through a small helper that raises argparse.ArgumentTypeError:

$ electrum --testnet --offline add_request help
run_electrum add_request: error: argument amount: invalid decimal value: 'help'

The special values (! for max, dryrun) are handled as before. Test: test_cli_decimal_args_reject_malformed_values in tests/test_commands.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI: add_request breaks without digits as first param

1 participant