#36210 streams: Include the OS error when AutoFile I/O fails

full analysis

https://github.com/bitcoin/bitcoin/pull/36210 · pablomartin4btc · +110/-5 in 3 files, 2 commits · labels: none

Goal

  • Include the underlying OS error message when file stream I/O operations fail
  • Help users and callers diagnose exact failure causes like missing permissions or full disks

Captures errno immediately after failed fread/fwrite calls in AutoFile and BufferedFile and appends the OS error message via SysErrorString() to thrown std::ios_base::failure exceptions. Adds unit test coverage in streams_tests to verify error string propagation across POSIX and Windows platforms.

Problem: AutoFile and BufferedFile throw fixed exception strings on real I/O failures, discarding errno and preventing callers from diagnosing why an I/O operation failed (such as out-of-space or permission errors).

Category: Utilities (logging, arguments, libraries) (#37 of 66)

P3 · diagnostics

  • P3 because it preserves errno to give meaningful failure details across the node
  • Provides a durable diagnostic improvement to shared file utilities without addressing critical bugs

Improves diagnostics on stream I/O failures across the node by preserving errno. While not fixing a critical bug or security issue, providing meaningful error reasons rather than generic failure messages is a clear, durable improvement to shared utility code.

Membership: Changes core stream primitives in src/streams.h and src/streams.cpp.

Factors: security/stability 0, bug 1, performance 0, user value 1, leverage 1

Reviewability: Ready

  • Ready for review
  • Small and self-contained with passing tests and no blockers

The PR is small, self-contained, tests pass, and there are no blockers or unaddressed reviewer requests.

Author status: active

Resolved concerns:

  • Alpine musl libc CI failure resolved by closing the file descriptor to trigger a genuine kernel-level EBADF rather than relying on libc-specific direction checks.

Agreement: Crickets

  • No reviews or concept feedback yet

No reviews or concept feedback yet

The PR has had no reviewer comments since opening.

Review verdicts (DrahtBot): 0

Dependencies

Enables:

  • Better error reporting for callers switching to AutoFile, such as wallet dump in #35492

Files

98 lines under test/bench/ci.

  • src/test/streams_tests.cpp +98/-0
  • src/streams.cpp +9/-4
  • src/streams.h +3/-1

Card

This PR updates AutoFile and BufferedFile stream implementations to capture errno on failing fread and fwrite calls, appending the formatted system error string to thrown std::ios_base::failure exceptions. This ensures error messages surfaced to logs and callers distinguish underlying OS causes such as out-of-space, bad descriptors, or permission issues. Comprehensive unit tests are added to verify error propagation across platforms. The pull request is clean, has passing CI, and currently awaits initial reviewer attention.

Data

dossier JSON · extract JSON · model openrouter/google/gemini-3.8-flash, generated 2026-09-17T16:23, confidence high, input hash 30b2ec6e66ebe6bc