I'm okay with the current approach too, but perhaps it would be more consistent to follow the layout of the Balances section, which is to make a dedicated Warnings header and then print each item underneath it, as opposed the first one next to it and the next one(s) underneath it? And then when the -deprecatedrpc=warnings option is removed in the future, no warnings will just not print anything in the output, which I think is nicer than "Warnings: (none)".
<details>
<summary>git diff on 59d0d24d6c</summary>
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index 1ee3c03431..865dd3e9c3 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -1517,10 +1517,12 @@ static void ParseGetInfoResult(UniValue& result)
}
const UniValue& warnings_value{result["warnings"]};
- const std::string warnings{warnings_value.isArray()
- ? Join(warnings_value.getValues(), "\n", [](const UniValue& warning) { return warning.get_str(); })
- : warnings_value.getValStr()};
- result_string += strprintf("%sWarnings:%s %s", YELLOW, RESET, warnings.empty() ? "(none)" : warnings);
+ if (warnings_value.isArray() && !warnings_value.empty()) {
+ result_string += strprintf("%sWarnings%s\n%s", YELLOW, RESET, Join(warnings_value.getValues(), "\n", [](const UniValue& warning) { return warning.get_str(); }));
+ } else {
+ const std::string warnings{warnings_value.getValStr()};
+ result_string += strprintf("%sWarnings:%s %s", YELLOW, RESET, warnings.empty() ? "(none)" : warnings);
+ }
result.setStr(result_string);
}
diff --git a/test/functional/interface_bitcoin_cli.py b/test/functional/interface_bitcoin_cli.py
index 47e9bdd4bd..cf07eec3fe 100755
--- a/test/functional/interface_bitcoin_cli.py
+++ b/test/functional/interface_bitcoin_cli.py
@@ -48,10 +48,12 @@ def cli_get_info_string_to_dict(cli_get_info_string):
line_idx = 0
while line_idx < len(lines):
line = lines[line_idx]
- if line.startswith("Warnings: "):
- # Warnings is the final section and can span multiple lines.
- cli_get_info["Warnings"] = "\n".join(lines[line_idx:]).removeprefix("Warnings: ")
- break
+ if line == "Warnings":
+ # When "Warnings" is a header line, all of the following lines contain one warning until an empty line
+ cli_get_info["Warnings"] = []
+ while line_idx + 1 < len(lines) and lines[line_idx + 1] != '':
+ line_idx += 1
+ cli_get_info["Warnings"].append(lines[line_idx])
elif "Balances" in line:
# When "Balances" appears in a line, all of the following lines contain "balance: wallet" until an empty line
cli_get_info["Balances"] = {}
@@ -243,8 +245,7 @@ class TestBitcoinCli(BitcoinTestFramework):
assert_equal(cli_get_info['Proxies'], network_info['networks'][0]['proxy'])
assert_equal(Decimal(cli_get_info['Difficulty']), blockchain_info['difficulty'])
assert_equal(cli_get_info['Chain'], blockchain_info['chain'])
- expected_warnings = "\n".join(network_info['warnings']) or "(none)"
- assert_equal(cli_get_info['Warnings'], expected_warnings)
+ assert_equal(cli_get_info['Warnings'], network_info['warnings'] or "(none)")
self.log.info("Test -getinfo and bitcoin-cli return all proxies")
self.restart_node(0, extra_args=["-proxy=127.0.0.1:9050", "-i2psam=127.0.0.1:7656"])
</details>