log: Nuke error(…) #29236

pull maflcko wants to merge 5 commits into bitcoin:master from maflcko:2401-log-error- changing 14 files +205 −110
  1. maflcko commented at 6:29 pm on January 11, 2024: member

    error(...) has many issues:

    • It is often used in the context of return error(...), implying that it has a “fancy” type, creating confusion with util::Result/Error
    • -logsourcelocations does not work with it, because it will pretend the error happened inside of logging.h
    • The log line contains ERROR: , as opposed to [error], like for other errors logged with LogError.

    Fix all issues by removing it.

  2. DrahtBot commented at 6:30 pm on January 11, 2024: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK fjahr, stickies-v, ryanofsky
    Concept ACK jamesob
    Stale ACK epiccurious, Empact

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #29538 (refactor: Improve naming of CBlock::GetHash() -> GetHeaderHash() by fjahr)
    • #29158 (PoC: fuzz chainstate and block managers by darosior)
    • #28955 (index: block filters sync, reduce disk read operations by caching last header by furszy)
    • #28945 (sync: improve CCoinsViewCache ReallocateCache by martinus)
    • #27006 (reduce cs_main scope, guard block index ’nFile’ under a local mutex by furszy)

    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.

  3. DrahtBot added the label Utils/log/libs on Jan 11, 2024
  4. jamesob commented at 8:05 pm on January 11, 2024: member
    Big Concept ACK. error() confuses me basically every time I run into it.
  5. DrahtBot added the label CI failed on Jan 11, 2024
  6. maflcko force-pushed on Jan 12, 2024
  7. DrahtBot removed the label CI failed on Jan 12, 2024
  8. DrahtBot added the label CI failed on Jan 15, 2024
  9. maflcko force-pushed on Jan 15, 2024
  10. DrahtBot removed the label CI failed on Jan 15, 2024
  11. in src/addrdb.cpp:68 in fa7658b8d1 outdated
    60@@ -60,7 +61,8 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
    61     if (fileout.IsNull()) {
    62         fileout.fclose();
    63         remove(pathTmp);
    64-        return error("%s: Failed to open file %s", __func__, fs::PathToString(pathTmp));
    65+        LogError("%s: Failed to open file %s\n", __func__, fs::PathToString(pathTmp));
    


    stickies-v commented at 1:13 pm on January 16, 2024:

    nit: it seems the return value from SerializeFileDB is never used to actually shut down the node. In the case of failing to open file, I think LogError is appropriate because that probably should lead to a shutdown. In the case of “Failed to flush file”, I think a LogWarning could be more appropriate.

    I think it’s best to leave the PR as is to make progress, bikeshedding over warning vs error categories doesn’t have a huge amount of benefit here. Just leaving this comment for visibility.


    maflcko commented at 2:43 pm on February 13, 2024:
    Yeah, but “error” is still applicable within the addrdb functions, as they can not continue and must return. So I think, ideally they’d return Result<void>, and the caller could downgrade the error to a warning and log it? Happy to review such a change, if someone creates it.
  12. stickies-v commented at 1:14 pm on January 16, 2024: contributor

    Approach ACK fa7658b8d190580eab385691a5e571035e399129

    I too have been confused by return error many a times.

  13. DrahtBot added the label Needs rebase on Jan 31, 2024
  14. maflcko force-pushed on Feb 1, 2024
  15. DrahtBot removed the label Needs rebase on Feb 1, 2024
  16. epiccurious commented at 3:18 am on February 11, 2024: none

    Concept ACK fa1d4f07c36dda3c72fb328918bddd7de062ef96.

    Fix all issues by removing it.

    Any conceivable downsides to removing it?

  17. maflcko commented at 12:08 pm on February 11, 2024: member

    Any conceivable downsides to removing it?

    I can’t see one, apart from the change consuming time to review it.

  18. in src/netbase.cpp:359 in fa1d4f07c3 outdated
    358@@ -358,14 +359,17 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
    359             return false;
    


    epiccurious commented at 4:07 pm on February 11, 2024:
    nit - Noticed this when reviewing the changes. Since we’re already changing the file - should Line 357/358 be a LogError not a LogPrintf?

    maflcko commented at 2:55 pm on February 13, 2024:
    If there are changes to other log lines, I’d say it would be best to do them in a separate pull request. The goal here is to be as close to a refactor as possible.
  19. in src/netbase.cpp:422 in fa1d4f07c3 outdated
    419+            LogError("Proxy failed to accept request\n");
    420+            return false;
    421         }
    422         if (pchRet2[1] != SOCKS5Reply::SUCCEEDED) {
    423             // Failures to connect to a peer that are not proxy errors
    424             LogPrintf("Socks5() connect to %s:%d failed: %s\n", strDest, port, Socks5ErrorString(pchRet2[1]));
    


    epiccurious commented at 4:22 pm on February 11, 2024:
    nit - Also noticed this when reviewing the changes. Since we’re already changing the file - should Line 413/422 be a LogError not a LogPrintf?

    maflcko commented at 2:45 pm on February 13, 2024:
    Why? This line is a failure to connect to a peer and the above are proxy errors. So keeping this as-is makes most sense. In any case, if there is a reason to change something unrelated in other lines, a separate pull request would be ideal.
  20. epiccurious approved
  21. epiccurious commented at 4:23 pm on February 11, 2024: none
    utACK fa1d4f07c36dda3c72fb328918bddd7de062ef96.
  22. DrahtBot requested review from stickies-v on Feb 11, 2024
  23. DrahtBot requested review from jamesob on Feb 11, 2024
  24. epiccurious commented at 10:16 pm on February 11, 2024: none

    Tested ACK fa1d4f07c36dda3c72fb328918bddd7de062ef96.

     0Options used to compile and link:
     1  external signer = yes
     2  multiprocess    = no
     3  with libs       = yes
     4  with wallet     = yes
     5    with sqlite   = yes
     6    with bdb      = yes
     7  with gui / qt   = yes
     8    with qr       = yes
     9  with zmq        = yes
    10  with test       = yes
    11  with fuzz binary = yes
    12  with bench      = yes
    13  with upnp       = no
    14  with natpmp     = no
    15  use asm         = yes
    16  USDT tracing    = no
    17  sanitizers      = 
    18  debug enabled   = no
    19  gprof enabled   = yes
    20  werror          = yes
    

    Passed test/functional/test_runner.py --extended. Please let me know if any of these skipped tests are relevant.

     0feature_bind_port_discover.py                          | ○ Skipped | 0 s
     1feature_bind_port_externalip.py                        | ○ Skipped | 1 s
     2feature_unsupported_utxo_db.py                         | ○ Skipped | 0 s
     3interface_usdt_coinselection.py                        | ○ Skipped | 0 s
     4interface_usdt_mempool.py                              | ○ Skipped | 0 s
     5interface_usdt_net.py                                  | ○ Skipped | 1 s
     6interface_usdt_utxocache.py                            | ○ Skipped | 0 s
     7interface_usdt_validation.py                           | ○ Skipped | 1 s
     8mempool_compatibility.py                               | ○ Skipped | 0 s
     9wallet_backwards_compatibility.py --descriptors        | ○ Skipped | 1 s
    10wallet_backwards_compatibility.py --legacy-wallet      | ○ Skipped | 0 s
    11wallet_inactive_hdchains.py --legacy-wallet            | ○ Skipped | 0 s
    12wallet_upgradewallet.py --legacy-wallet                | ○ Skipped | 0 s
    13
    14ALL                                                    | ✓ Passed  | 6598 s (accumulated) 
    
  25. stickies-v approved
  26. stickies-v commented at 7:25 am on February 15, 2024: contributor
    ACK fa1d4f07c36dda3c72fb328918bddd7de062ef96
  27. ryanofsky approved
  28. ryanofsky commented at 3:17 pm on February 15, 2024: contributor

    Code review ACK fa1d4f07c36dda3c72fb328918bddd7de062ef96

    This is a nice improvement, and it actually doesn’t change many lines of code, so I don’t think we should be worried about conflicts if we want to make more improvements later, like changing log levels, or adding categories, or switching to util::Result.

    One thing I think we probably should revisit after this is the interaction with -logsourcelocations, since it seems like a lot (maybe most?) of the new LogError calls are manually adding “%s: “, __func__ prefixes to the log, which shows the function name in a different format than -logsourcelocations, and also includes the function name twice if -logsourcelocations is enabled. A way to improve this might be to add an option to LogError to make it log the source location even if -logsourcelocations is not turned on. Or maybe it would be better if the error messages were more descriptive and didn’t rely on the function names to provide context.

  29. fjahr commented at 5:48 pm on February 18, 2024: contributor

    utACK fa1d4f07c3

    There is still a reference to error in the comments in logging.h: https://github.com/fjahr/bitcoin/commit/6457d77e39a8c07fdef798f3bf115fcbb30545c4 But removing it can be kept for a follow-up.

  30. maflcko added this to the milestone 28.0 on Feb 22, 2024
  31. Empact approved
  32. Empact commented at 5:20 pm on February 27, 2024: member
    Code review ACK fa1d4f07c36dda3c72fb328918bddd7de062ef96
  33. stickies-v commented at 2:20 pm on March 1, 2024: contributor
    I think this is RFM?
  34. fanquake commented at 2:48 pm on March 1, 2024: member
    It conflicts with something that will be merged after branch-off.
  35. DrahtBot added the label Needs rebase on Mar 9, 2024
  36. refactor: Add missing {} around error() calls
    This is required for the next commit to be correct.
    fa9a5e80ab
  37. scripted-diff: return error(...); ==> error(...); return false;
    This is needed for the next commit.
    
    -BEGIN VERIFY SCRIPT-
     # Separate sed invocations to replace one-line, and two-line error(...) calls
     sed -i             --regexp-extended 's!( +)return (error\(.*\);)!\1\2\n\1return false;!g'             $( git grep -l 'return error(' )
     sed -i --null-data --regexp-extended 's!( +)return (error\([^\n]*\n[^\n]*\);)!\1\2\n\1return false;!g' $( git grep -l 'return error(' )
    -END VERIFY SCRIPT-
    fa1d624348
  38. refactor: Make error() return type void
    This is needed for the next commit to compile.
    fa808fb749
  39. scripted-diff: Replace error() with LogError()
    This fixes the log output when -logsourcelocations is used.
    
    Also, instead of 'ERROR:', the log will now say '[error]', like other
    errors logged with LogError.
    
    -BEGIN VERIFY SCRIPT-
     sed -i --regexp-extended 's!  error\("([^"]+)"!  LogError("\1\\n"!g' $( git grep -l '  error(' ./src/ )
    -END VERIFY SCRIPT-
    fad0335517
  40. refactor: Remove unused error() fa39151394
  41. maflcko force-pushed on Mar 11, 2024
  42. maflcko commented at 1:14 pm on March 11, 2024: member

    rebased.

    Should be trivial to re-ACK, as no lines touched by this are affected (only one tangent line)

  43. fjahr commented at 1:35 pm on March 11, 2024: contributor

    re-utACK fa391513949b7a3b56321436e2015c7e9e6dac2b

    Based on git range-diff master fa1d4f07c36dda3c72fb328918bddd7de062ef96 fa391513949b7a3b56321436e2015c7e9e6dac2b.

  44. DrahtBot requested review from epiccurious on Mar 11, 2024
  45. DrahtBot requested review from Empact on Mar 11, 2024
  46. DrahtBot requested review from stickies-v on Mar 11, 2024
  47. DrahtBot requested review from ryanofsky on Mar 11, 2024
  48. stickies-v commented at 1:47 pm on March 11, 2024: contributor
    re-ACK fa391513949b7a3b56321436e2015c7e9e6dac2b, no changes since 4a903741b0
  49. DrahtBot removed review request from stickies-v on Mar 11, 2024
  50. DrahtBot removed review request from epiccurious on Mar 11, 2024
  51. DrahtBot requested review from epiccurious on Mar 11, 2024
  52. DrahtBot removed the label Needs rebase on Mar 11, 2024
  53. ryanofsky commented at 3:38 pm on March 11, 2024: contributor
    Code review ACK fa391513949b7a3b56321436e2015c7e9e6dac2b. Just rebase since last review
  54. fanquake merged this on Mar 12, 2024
  55. fanquake closed this on Mar 12, 2024

  56. maflcko deleted the branch on Mar 12, 2024
  57. fanquake referenced this in commit 1105aa46dd on Mar 12, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-21 09:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me