restrict std::cerr to errors; use std::cout for warnings and info #32538

pull furszy wants to merge 2 commits into bitcoin:master from furszy:2025_init_warning_msgs changing 3 files +49 −16
  1. furszy commented at 6:42 pm on May 16, 2025: member

    Warning messages were previously sent to stderr, which could cause them to be misinterpreted as actual errors. This change redirects warning and informational messages to stdout instead, making it explicit that they are not errors and preventing unintended stderr handling.

    To verify this behavior, added a test case triggering the simplest init warning I could find (one that was actually not previously covered by tests): the -bind “bad-port” message. So, running the test commit on master (without the fix) causes the test framework to fail during shutdown due to a non-empty stderr buffer (treated as an error). With the fix applied, the warning is correctly handled via stdout, and the test passes as expected.

  2. init: restrict std::cerr to errors; use std::cout for warnings and info
    Warning messages were previously sent to std::cerr, which could cause them
    to be treated as errors when they are not. This change pipes warning and
    informational messages through std::cout instead, making it clearer that
    they are not errors.
    4ff27834e3
  3. test: add coverage to ensure init warnings aren't treated as errors
    Verifies that the bad-ports warning is no longer misinterpreted as an error.
    Previously, it was sent through std::cerr, causing the test framework to wrongly
    classify it as an error during shutdown. Now that the message is routed through
    std::cout, this test confirms that warnings are handled properly and do not
    trigger false failures.
    9e9b16523f
  4. DrahtBot commented at 6:42 pm on May 16, 2025: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32538.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK pablomartin4btc

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

  5. maflcko commented at 7:00 pm on May 16, 2025: member

    Warning messages were previously sent to stderr, which could cause them to be misinterpreted as actual errors.

    Not sure.

    • When something literally starts with Warning: ..., I fail to see how it can be misinterpreted.
    • This change means that warnings may be missed in tests/CI or elsewhere (see the failing CI).
    • Sending warnings to stderr is normal and expected. See for example python -c 'print(b"\p")'
  6. pablomartin4btc commented at 7:01 pm on May 16, 2025: member

    Concept ACK

    I think some tests using stop_node with the warning in the args would fail as in is_node_stopped checks for the warning in stderr (eg wallet_multiwallet.py), it needs to be fixed too.

  7. pablomartin4btc commented at 7:03 pm on May 16, 2025: member

    This change means that warnings may be missed in tests/CI or elsewhere (see the failing CI).

    That’s my concern with this approach.

  8. furszy commented at 7:24 pm on May 16, 2025: member

    When something literally starts with Warning: …, I fail to see how it can be misinterpreted.

    It is actually being misinterpreted by our own test framework. The framework does not look at the stderr content, it only checks whether there is something inside stderr or not during shutdown, failing when finds something there.

    This change means that warnings may be missed in tests/CI or elsewhere (see the failing CI).

    That’s ok. That’s what the PR is proposing. To redirect them to stdout. I just missed to update some test cases that are working around the stderr issue during cleanup by manually skipping warning msgs during shutdown.

    Sending warnings to stderr is normal and expected. See for example python -c ‘print(b"\p")’

    This is the most compelling argument of the three. You got me there. Closing..

  9. furszy closed this on May 16, 2025

  10. maflcko commented at 6:19 am on May 17, 2025: member

    When something literally starts with Warning: …, I fail to see how it can be misinterpreted.

    It is actually being misinterpreted by our own test framework. The framework does not look at the stderr content, it only checks whether there is something inside stderr or not during shutdown, failing when finds something there.

    That’s intentional. We want the tests to fail when there is any warning or error (from Bitcoin Core or any other tool/sanitizer/lib) that is not accounted for, so that they are properly documented, investigated and accounted for.

  11. fanquake commented at 10:20 am on May 17, 2025: member

    We want the tests to fail when there is any warning or error (from Bitcoin Core or any other tool/sanitizer/lib) that is not accounted for

    Opened #32542 in relation to this.


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: 2025-05-25 18:12 UTC

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