Skip to content

Commit 2dede9f

Browse files
committed
Adjust RPCTypeCheckObj error string
1 parent 9ca39d6 commit 2dede9f

File tree

6 files changed

+9
-12
lines changed

6 files changed

+9
-12
lines changed

src/rpc/util.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,8 @@ void RPCTypeCheckObj(const UniValue& o,
6565
if (!fAllowNull && v.isNull())
6666
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing %s", t.first));
6767

68-
if (!(t.second.typeAny || v.type() == t.second.type || (fAllowNull && v.isNull()))) {
69-
std::string err = strprintf("Expected type %s for %s, got %s",
70-
uvTypeName(t.second.type), t.first, uvTypeName(v.type()));
71-
throw JSONRPCError(RPC_TYPE_ERROR, err);
72-
}
68+
if (!(t.second.typeAny || v.type() == t.second.type || (fAllowNull && v.isNull())))
69+
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("JSON value of type %s for field %s is not of expected type %s", uvTypeName(v.type()), t.first, uvTypeName(t.second.type)));
7370
}
7471

7572
if (fStrict)

test/functional/rpc_fundrawtransaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ def test_option_feerate(self):
793793

794794
self.log.info("Test fundrawtxn with invalid estimate_mode settings")
795795
for k, v in {"number": 42, "object": {"foo": "bar"}}.items():
796-
assert_raises_rpc_error(-3, "Expected type string for estimate_mode, got {}".format(k),
796+
assert_raises_rpc_error(-3, f"JSON value of type {k} for field estimate_mode is not of expected type string",
797797
node.fundrawtransaction, rawtx, {"estimate_mode": v, "conf_target": 0.1, "add_inputs": True})
798798
for mode in ["", "foo", Decimal("3.141592")]:
799799
assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"',
@@ -803,7 +803,7 @@ def test_option_feerate(self):
803803
for mode in ["unset", "economical", "conservative"]:
804804
self.log.debug("{}".format(mode))
805805
for k, v in {"string": "", "object": {"foo": "bar"}}.items():
806-
assert_raises_rpc_error(-3, "Expected type number for conf_target, got {}".format(k),
806+
assert_raises_rpc_error(-3, f"JSON value of type {k} for field conf_target is not of expected type number",
807807
node.fundrawtransaction, rawtx, {"estimate_mode": mode, "conf_target": v, "add_inputs": True})
808808
for n in [-1, 0, 1009]:
809809
assert_raises_rpc_error(-8, "Invalid conf_target, must be between 1 and 1008", # max value of 1008 per src/policy/fees.h

test/functional/rpc_mempool_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def create_tx(**kwargs):
8484
assert_raises_rpc_error(-8, "Invalid parameter, vout cannot be negative", self.nodes[0].gettxspendingprevout, [{'txid' : txidA, 'vout' : -1}])
8585

8686
self.log.info("Invalid txid provided")
87-
assert_raises_rpc_error(-3, "Expected type string for txid, got number", self.nodes[0].gettxspendingprevout, [{'txid' : 42, 'vout' : 0}])
87+
assert_raises_rpc_error(-3, "JSON value of type number for field txid is not of expected type string", self.nodes[0].gettxspendingprevout, [{'txid' : 42, 'vout' : 0}])
8888

8989
self.log.info("Missing outputs")
9090
assert_raises_rpc_error(-8, "Invalid parameter, outputs are missing", self.nodes[0].gettxspendingprevout, [])

test/functional/rpc_psbt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def run_test(self):
272272

273273
self.log.info("- raises RPC error with invalid estimate_mode settings")
274274
for k, v in {"number": 42, "object": {"foo": "bar"}}.items():
275-
assert_raises_rpc_error(-3, "Expected type string for estimate_mode, got {}".format(k),
275+
assert_raises_rpc_error(-3, f"JSON value of type {k} for field estimate_mode is not of expected type string",
276276
self.nodes[1].walletcreatefundedpsbt, inputs, outputs, 0, {"estimate_mode": v, "conf_target": 0.1, "add_inputs": True})
277277
for mode in ["", "foo", Decimal("3.141592")]:
278278
assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"',
@@ -282,7 +282,7 @@ def run_test(self):
282282
for mode in ["unset", "economical", "conservative"]:
283283
self.log.debug("{}".format(mode))
284284
for k, v in {"string": "", "object": {"foo": "bar"}}.items():
285-
assert_raises_rpc_error(-3, "Expected type number for conf_target, got {}".format(k),
285+
assert_raises_rpc_error(-3, f"JSON value of type {k} for field conf_target is not of expected type number",
286286
self.nodes[1].walletcreatefundedpsbt, inputs, outputs, 0, {"estimate_mode": mode, "conf_target": v, "add_inputs": True})
287287
for n in [-1, 0, 1009]:
288288
assert_raises_rpc_error(-8, "Invalid conf_target, must be between 1 and 1008", # max value of 1008 per src/policy/fees.h

test/functional/wallet_bumpfee.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def test_invalid_parameters(self, rbf_node, peer_node, dest_address):
151151

152152
self.log.info("Test invalid estimate_mode settings")
153153
for k, v in {"number": 42, "object": {"foo": "bar"}}.items():
154-
assert_raises_rpc_error(-3, "Expected type string for estimate_mode, got {}".format(k),
154+
assert_raises_rpc_error(-3, f"JSON value of type {k} for field estimate_mode is not of expected type string",
155155
rbf_node.bumpfee, rbfid, {"estimate_mode": v})
156156
for mode in ["foo", Decimal("3.1415"), "sat/B", "BTC/kB"]:
157157
assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"',

test/functional/wallet_send.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def run_test(self):
362362
for mode in ["economical", "conservative"]:
363363
for k, v in {"string": "true", "bool": True, "object": {"foo": "bar"}}.items():
364364
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, conf_target=v, estimate_mode=mode,
365-
expect_error=(-3, f"Expected type number for conf_target, got {k}"))
365+
expect_error=(-3, f"JSON value of type {k} for field conf_target is not of expected type number"))
366366

367367
# Test setting explicit fee rate just below the minimum of 1 sat/vB.
368368
self.log.info("Explicit fee rate raises RPC error 'fee rate too low' if fee_rate of 0.99999999 is passed")

0 commit comments

Comments
 (0)