Summary
cmd_balance, cmd_history, cmd_miners, and cmd_epoch in tools/rustchain_wallet_cli.py all call r.json() directly without first verifying that the HTTP response body is valid JSON. When the server returns a non-JSON error (e.g., 502 Bad Gateway with an HTML body, or a plain-text 503 Service Unavailable), a requests.exceptions.JSONDecodeError propagates out of the function.
Although main() catches Exception, the resulting error message (Expecting value: line 1 column 1 (char 0)) gives the user zero context about what actually went wrong.
Affected code
tools/rustchain_wallet_cli.py – functions: cmd_balance, cmd_history, cmd_miners, cmd_epoch, cmd_send
# cmd_balance (line ~175)
r = requests.get(url, params={"miner_id": args.wallet_id}, timeout=12, verify=VERIFY_SSL)
data = r.json() # <-- crashes if server returns HTML/text on error
Steps to reproduce
# Point at a non-existent or misconfigured node
export RUSTCHAIN_NODE_URL=https://httpbin.org/status/502
python -m tools.rustchain_wallet_cli balance RTCabc123
Expected behavior: A clear error message such as Error: Server returned HTTP 502 (check node URL/connectivity).
Actual behavior:
Error: Expecting value: line 1 column 1 (char 0)
Fix
Call r.raise_for_status() before r.json(), or wrap the JSON decode in a try/except that re-raises with the HTTP status code included.
r = requests.get(url, params={"miner_id": args.wallet_id}, timeout=12, verify=VERIFY_SSL)
try:
data = r.json()
except requests.exceptions.JSONDecodeError:
print(f"Error: Server returned HTTP {r.status_code} with non-JSON body", file=sys.stderr)
return 1
Labels
bug, wallet, error-handling
Summary
cmd_balance,cmd_history,cmd_miners, andcmd_epochintools/rustchain_wallet_cli.pyall callr.json()directly without first verifying that the HTTP response body is valid JSON. When the server returns a non-JSON error (e.g.,502 Bad Gatewaywith an HTML body, or a plain-text503 Service Unavailable), arequests.exceptions.JSONDecodeErrorpropagates out of the function.Although
main()catchesException, the resulting error message (Expecting value: line 1 column 1 (char 0)) gives the user zero context about what actually went wrong.Affected code
tools/rustchain_wallet_cli.py– functions:cmd_balance,cmd_history,cmd_miners,cmd_epoch,cmd_sendSteps to reproduce
Expected behavior: A clear error message such as
Error: Server returned HTTP 502 (check node URL/connectivity).Actual behavior:
Fix
Call
r.raise_for_status()beforer.json(), or wrap the JSON decode in a try/except that re-raises with the HTTP status code included.Labels
bug, wallet, error-handling