New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpc, test: remove newline escape sequence from wallet warning fields #27138
rpc, test: remove newline escape sequence from wallet warning fields #27138
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
ed0a983
to
6367e69
Compare
Updated for |
Concept ACK
I think they all do, check the code in
|
in RPCs createwallet, loadwallet, unloadwallet, and restorewallet.
6367e69
to
f0391cd
Compare
Thanks @TheCharlatan, updated the OP and commit message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK f0391cd
Was a bit hesitant about adding the messages to the functional tests, but I think testing the correct concatenation kind of makes sense.
Code changes and tests look OK to me I found a few other similar mechanisms in other modules, dunno if this change should apply to them as well: Lines 55 to 57 in 82793f1
Lines 2565 to 2569 in 82793f1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK f0391cd
-0. Showing \n on the terminal seems like a client side problem not a server side problem, and this server-side change makes it harder for other clients besides bitcoin-cli to display the warnings clearly on separate lines. IMO, the ideal fix for this would be for |
@ryanofsky Adding newlines is a client-side presentation concern. If it is important for the RPC client to know how many warnings have been returned in order to display them on separate lines, it seems best after this to gradually replace the @pinheadmz (Thanks!) Saw those for (maybe, maybe not) another pull; prefer to keep this small and focused. |
If they are the same issue, what's the reasoning for leaving them for another PR? Not sure how the PR becomes less focused by fixing more of the same problem. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK f0391cd
The newline is presentation-specific and does not belong to the server output. For example it will not render as expected if displayed in HTML (where newlines are displayed as a single space). Then it should be <br/>
instead of \n
, or maybe \r\n
for MacOS?
I am happy to review more of the same in another PR or a change that returns an array of warnings so that display engines can chose the best separator for them.
Again, for the record, I disagree. The RPC server does not return HTML strings or XML strings, it returns text strings, and the newline character has a very clear meaning in text strings. Newline is a better delimiter than space if there are multiple warnings, so they are separable and coherent. Replacing newlines with spaces produces addled run-on paragraphs like "Wallet will not be encrypted. Wallet created successfully. The legacy wallet type..."). Newlines are better than spaces for RPC clients that know how to output text, so it is unfortunate that the bitcoin-cli client doesn't know which fields are text fields and dumps the warnings as JSON encoded text instead. I do appreciate that bitcoin-cli specifically has a problem here. But I think teaching bitcoin-cli that the result["warning"] field is a text field, or teaching it to colorize JSON output, or adding a result["warnings"] list field would be better solutions that don't hurt other clients for the sake of helping bitcoin-cli. |
I agree with @ryanofsky that this is a client side issue which should be fixed in the client and not the server. I also prefer that we remove |
I think we all agree with adding a |
The output would be the following, which seems fine to me: |
If the documentation for the field is unclear, what about changing the help text over changing the code? |
Thanks for the reviews, everyone. I'm not sure it makes sense to patch around this by adding code to our CLI to parse newline escape sequences, as that would be adding unneeded complexity for 4 messages instead of fixing the problem at the source in 4 LOC, adding complexity for something that's probably going away anyway (here and/or replaced eventually by Elaborating that last point, the 4 escape sequences were added in pulls like #15937 without warning for client software to parse for them. While it is within the JSON standard to use them, unless API clients do better QA testing than Bitcoin Core it seems doubtful that clients detected the need for and added newline-delimited JSON string handling for a handful of messages out of many returned by our API. After all, we didn't, so perhaps it's a high ask. It also seems clear that a paragraph of several sentences causes less user astonishment than the same paragraph with For similar reasons, I'm not sure that adding documentation to I'll propose a |
Yes agree no need for this as we already have a JSON parser. CLI could see simply if check result object has This would be really simple, and make warnings more obvious and readable, and be compatible with other bitcoin-cli improvements in the future. |
If these four remaining "warning" fields are behind a deprecation flag (opening a PR today), hopefully that avoids the need to do anything further, unless we want to backport a fix. I'll look into that. |
Circling back for completeness to cover a few questions/suggestions.
This code appends warning messages to the
The diff
--- a/src/warnings.cpp
+++ b/src/warnings.cpp
@@ -47,10 +47,14 @@ bilingual_str GetWarnings(bool verbose)
warnings_verbose.emplace_back(warnings_concise);
}
- if (fLargeWorkInvalidChainFound) {
- warnings_concise = _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.");
- warnings_verbose.emplace_back(warnings_concise);
- }
+ warnings_concise = _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.");
+ warnings_verbose.emplace_back(warnings_concise);
+
+ warnings_concise = _("Warning: Low on disk space.");
+ warnings_verbose.emplace_back(warnings_concise);
+
+ warnings_concise = _("Warning: System clock is off.");
+ warnings_verbose.emplace_back(warnings_concise);
if (verbose) {
return Join(warnings_verbose, Untranslated("<hr />"));
I am not sure, but this seems a little kludgey; more so if we're going to remove these fields anyway. I think I prefer either the approach in this PR or documenting Am addressing the feedback above and will post here when it's ready. |
Based on the discussion above, #27279 is now ready. It adds a |
…create,load,unload,restore}wallet 7ccdd74 test: fix importmulti/importdescriptors assertion (Jon Atack) 19d888c rpc: move WALLET_FLAG_CAVEATS to the compilation unit of its caller (Jon Atack) 01df011 doc: release note for wallet RPCs "warning" field deprecation (Jon Atack) 9ea8b37 test: createwallet "warning" field deprecation test (Jon Atack) 645d7f7 rpc: deprecate "warning" field in {create,load,unload,restore}wallet (Jon Atack) 2f4a926 test: add test coverage for "warnings" field in createwallet (Jon Atack) 4a1e479 rpc: add "warnings" field to RPCs {create,load,unload,restore}wallet (Jon Atack) 079d8cd rpc: extract wallet "warnings" fields to a util helper (Jon Atack) f73782a doc: fix/improve warning helps in {create,load,unload,restore}wallet (Jon Atack) Pull request description: Based on discussion and concept ACKed in #27138, add a `warnings` field to RPCs createwallet, loadwallet, unloadwallet, and restorewallet as a JSON array of strings to replace the `warning` string field in these 4 RPCs. The idea is to more gracefully handle multiple warning messages and for consistency with other wallet RPCs. Then, deprecate the latter fields, which represent all the remaining RPC `warning` fields. The first commit bitcoin/bitcoin@f73782a implements bitcoin/bitcoin#27138 (comment) as an alternative to #27138. One of those two could potentially be backported to our currently supported releases. ACKs for top commit: achow101: ACK 7ccdd74 1440000bytes: utACK bitcoin/bitcoin@7ccdd74 vasild: ACK 7ccdd74 pinheadmz: re-ACK 7ccdd74 Tree-SHA512: 314e0a4c41fa383d95e2817bfacf359d449e460529d235c3eb902851e2f4eacbabe646d9a5a4beabc4964cdfabf6397ed8301366a58d344a2f787f83b75e9d64
Superceded by #27279. Thanks everyone! |
This PR extends our test coverage to demonstrate the issue, then removes newline escape sequences printed in the wallet
warning
field in RPCscreatewallet
,loadwallet
,unloadwallet
, andrestorewallet
.before
after
Rationale: Our RPC is returning newline presentation elements embedded in JSON string field responses. These are a client-side concern, not a server-side one. If it is important for the RPC client to know how many warnings have been returned in order to display them on separate lines, then it may be a good idea after this to gradually replace the
warning
string field with awarnings
JSON array of strings, as we do in several other RPCs. I'm happy to do that in a follow-up, as it would be orthogonal to this change: first thewarnings
field would be added and thewarning
field deprecated, then after a release or so the latter could possibly be removed. In the meantime, this is a simple and focused fix.