Skip to content

fix: consistent error handling + exit codes in wallet balance check CLI [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] - #8088

Open
waterWang wants to merge 1 commit into
Scottcjn:mainfrom
waterWang:fix/consistent-error-handling-16253
Open

fix: consistent error handling + exit codes in wallet balance check CLI [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT]#8088
waterWang wants to merge 1 commit into
Scottcjn:mainfrom
waterWang:fix/consistent-error-handling-16253

Conversation

@waterWang

@waterWang waterWang commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Changes

Fixes two error-handling inconsistencies in tools/rustchain_wallet_cli.py (bounty rustchain-bounties#16253).

1. cmd_export — explicit error handling for missing wallet

Previously, cmd_export let _load_keystore's FileNotFoundError bubble up to main()'s catch-all, which returned the generic EXIT_UNKNOWN_ERROR (6). Now it returns EXIT_WALLET_NOT_FOUND (4) with a clear error message, matching the pattern used by cmd_send.

2. main() catch-all — consistent error message casing

Changed "Error: {e}" (lowercase) to "ERROR: {e}" (uppercase) to match the consistent uppercase style used by every other error path (cmd_balance, cmd_send, cmd_history, cmd_miners, cmd_epoch).

3. Comprehensive test coverage (15 new tests)

Added tests/test_wallet_cli_error_handling_16253.py covering every failure path:

Command Path Expected Exit Code
_safe_json Non-JSON body (502) EXIT_BAD_RESPONSE (3)
_safe_json_object JSON array where object expected EXIT_BAD_RESPONSE (3)
cmd_balance Network error EXIT_NETWORK_ERROR (2)
cmd_balance 404 not found EXIT_WALLET_NOT_FOUND (4)
cmd_balance 500 server error EXIT_BAD_RESPONSE (3)
cmd_balance Malformed JSON body EXIT_BAD_RESPONSE (3)
cmd_balance Missing amount field EXIT_BAD_RESPONSE (3)
cmd_balance balance_rtc alias (happy path) EXIT_SUCCESS (0)
cmd_export Missing wallet EXIT_WALLET_NOT_FOUND (4)
cmd_history Network error EXIT_NETWORK_ERROR (2)
cmd_history 404 not found EXIT_WALLET_NOT_FOUND (4)
cmd_history 500 server error EXIT_BAD_RESPONSE (3)
cmd_send Missing wallet EXIT_WALLET_NOT_FOUND (4)
cmd_send Network error EXIT_NETWORK_ERROR (2)

Specific inconsistencies addressed (from #7889)

  • cmd_export: FileNotFoundError bubbled to main() catch-all → returned wrong exit code (6 instead of 4)
  • main(): lowercase "Error: {e}" inconsistent with uppercase "ERROR: " everywhere else
  • All failure paths now write to stderr with clear error message and appropriate non-zero exit code
  • Exit code scheme already documented in --help epilog

Verification

  • python3 -m pytest tests/test_wallet_cli_39.py tests/test_wallet_cli_error_handling_16253.py --noconftest -v → 31/31 passed
  • No behavior change on the happy path

Closes #7889
Closes Scottcjn/rustchain-bounties#16253

@github-actions

Copy link
Copy Markdown
Contributor

Welcome to RustChain! Thanks for your first pull request.

Before we review, please make sure:

  • Non-doc PRs have a BCOS-L1 or BCOS-L2 label
  • Doc-only PRs are exempt from BCOS tier labels when they only touch docs/**, *.md, or common image/PDF files
  • New code files include an SPDX license header
  • You've tested your changes against the live node

Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150)

A maintainer will review your PR soon. Thanks for contributing!

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) size/L PR: 201-500 lines labels Jul 28, 2026
…LI [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT]

Fixes two inconsistencies in tools/rustchain_wallet_cli.py (bounty #16253):

1. cmd_export: add explicit FileNotFoundError handling so missing
   wallet returns EXIT_WALLET_NOT_FOUND (4) instead of the generic
   EXIT_UNKNOWN_ERROR (6) from main()'s catch-all.

2. main(): Change lowercase 'Error: {e}' to uppercase 'ERROR: {e}'
   to match the consistent uppercase style used by every other error
   path in the CLI (cmd_balance, cmd_send, cmd_history, etc.).

3. Add 15 tests covering every failure path in cmd_balance, cmd_export,
   cmd_send, cmd_history, _safe_json, and _safe_json_object — network
   errors, 404, 500, malformed JSON, missing fields, missing wallet.

Closes Scottcjn#7889
Closes Scottcjn/rustchain-bounties#16253
@waterWang
waterWang force-pushed the fix/consistent-error-handling-16253 branch from a625f50 to 32ee667 Compare July 29, 2026 07:26
@waterWang
waterWang requested a review from Scottcjn as a code owner July 29, 2026 07:26
@github-actions github-actions Bot added the tests Test suite changes label Jul 29, 2026
@waterWang waterWang changed the title fix: consistent error handling + exit codes in wallet balance check script (#16253) [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] fix: consistent error handling + exit codes in wallet balance check CLI [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) size/L PR: 201-500 lines tests Test suite changes

Projects

None yet

1 participant