Skip to content

Commit 1e2d2d1

Browse files
committed
Reword confusing warning message in RPC linter
Summary: It's easy to come across this message by simply forgetting to add an entry in `src/rpc/client.cpp` when an argument name matches an existing entry in that table. This patch clarifies both the intent and reason for the warning, and suggests possible fixes. Test Plan: Add this line to `commands` in `src/rpc/avalanche.cpp`: `{ "avalanche", "addavalanchepeer", addavalanchepeer, {"nodeid"}},` `arc lint src/rpc/avalance.cpp` will fail with the warning message (note "nodeid" conflicts with disconnectnode's "nodeid") Add this line to the table in `src/rpc/client.cpp`: `{"addavalanchepeer", 0, "nodeid"},` `arc lint src/rpc/avalance.cpp` passes Example output: ``` >>> Lint for /home/jasonbcox/projects/bitcoin-abc: Warning (RPC_MAPPING_WARNING) RPC mapping warning In order to keep a consistent API, arguments of the same name are expected to either both be string-typed or converted from JSON. But there was a conversion mismatch: ["'getavalanchekey' has argument 'nodeid' of type 'string'", "'disconnectnode' has argument 'nodeid' of type 'JSON'"]. Common root causes for this warning: 1) The command and/or argument are missing from the conversion table in 'src/rpc/client.cpp'. 2) Arguments of the same name are being converted from JSON for some commands, but not for others. Consider renaming arguments such that one name is used for strings and the other for conversions from JSON. ``` Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Subscribers: deadalnix Differential Revision: https://reviews.bitcoinabc.org/D5659
1 parent d16ea8a commit 1e2d2d1

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

test/lint/check-rpc-mappings.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,21 @@ def main():
169169
if argname in IGNORE_DUMMY_ARGS:
170170
# these are testing or dummy, don't warn for them
171171
continue
172-
print('WARNING: conversion mismatch for argument named {} ({})'.format(
173-
argname, list(zip(all_methods_by_argname[argname], converts_by_argname[argname]))))
172+
formattedCommands = []
173+
for (cmd, convert) in list(
174+
zip(all_methods_by_argname[argname], converts_by_argname[argname])):
175+
argType = 'string'
176+
if convert:
177+
argType = 'JSON'
178+
formattedCommands.append(
179+
"'{}' has argument '{}' of type '{}'".format(
180+
cmd, argname, argType))
181+
print("WARNING: In order to keep a consistent API, arguments of the same name are expected to either both "
182+
"be string-typed or converted from JSON. But there was a conversion mismatch: {}. "
183+
"Common root causes for this warning: 1) The command and/or argument are missing from the conversion "
184+
"table in '{}'. 2) Arguments of the same name are being converted from JSON for some commands, but not "
185+
"for others. Consider renaming arguments such that one name is used for strings and the other for "
186+
"conversions from JSON.".format(formattedCommands, SOURCE_CLIENT))
174187

175188
sys.exit(0)
176189

0 commit comments

Comments
 (0)