bit of a nit. removes redundant logic check and make more readable.
summary of changes:
old: status >= 400 && status != 400
new: status > 400
bit of a nit. removes redundant logic check and make more readable.
summary of changes:
old: status >= 400 && status != 400
new: status > 400
Can you fixup the linter issue:
This diff appears to have added new lines with tab characters instead of spaces.
The following changes were suspected:
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
@@ -399 +399,3 @@ static UniValue CallRPC(BaseRequestHandler *rh, const std::string& strMethod, co
+ && response.status != HTTP_NOT_FOUND
+ && response.status != HTTP_INTERNAL_SERVER_ERROR)
^---- failure generated from test/lint/lint-whitespace.sh
remove redundant check and make more readable
linter is now passing.
Welcome as a Bitcoin Core contributor @niftynei. Thanks for all the great c-lightning contributions you've done!
395 | @@ -396,7 +396,9 @@ static UniValue CallRPC(BaseRequestHandler *rh, const std::string& strMethod, co 396 | } else { 397 | throw std::runtime_error("Authorization failed: Incorrect rpcuser or rpcpassword"); 398 | } 399 | - } else if (response.status >= 400 && response.status != HTTP_BAD_REQUEST && response.status != HTTP_NOT_FOUND && response.status != HTTP_INTERNAL_SERVER_ERROR) 400 | + } else if (response.status > HTTP_BAD_REQUEST // HTTP_BAD_REQUEST is 400 401 | + && response.status != HTTP_NOT_FOUND
nit: 5 spaces of extra indentation?
are wrapped if's usually lined up? this seems to odd to me but i'm not familiar with bitcoind's formatting conventions.
the linter didn't complain, so there's that, in theory it's https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#coding-style-c
ACK on hoisting the magic value to a constant. The original logic began by checking that there is an HTTP error (either Client 4xx or Server 5xx), and then enumerating the 3 exceptions; I suppose this was done to separate the general error class check from the HTTP_BAD_REQUEST check. Maybe good to keep this separation?
I suppose this was done to separate the general error class check from the HTTP_BAD_REQUEST check. Maybe good to keep this separation?
This is why I added the comment. If we keep the constant but revert the logic, I don't think that's going to make what it's doing any clearer.
the CI job failure appears to be spurious
I surmise the intent was if status >= HTTP_ERROR && (specific exceptions we want to handle differently) so if the exceptions change it seems good to keep the general check separate along the lines of:
} else if (response.status >= HTTP_ERROR &&
(response.status != HTTP_BAD_REQUEST &&
response.status != HTTP_NOT_FOUND &&
response.status != HTTP_INTERNAL_SERVER_ERROR)) {
but that's only one opinion :)
The change is correct but FWIW I prefer the current one.
I also prefer the current code - if 400 is "the value that identifies all errors", then what follows are exceptions to the general error condition.
The change is correct but FWIW I prefer the current one.
I also prefer the current code - if 400 is "the value that identifies all errors", then what follows are exceptions to the general error condition.
Same. I like that this splits the condition over multiple lines, but I don't like the >= to > change as it makes things less explicit. There's no need for this kind of manual logic optimization, wouldn't be surprised if the compiled code is exactly the same.
I also don't think replacing the 400 with a constant is good. ">= 400" is used as shortcut for "4xx or 5xx" here, which are the HTTP error codes that are fatal.
I don't think there's enough agreement to make this change. Closing, sorry.