Skip to content

Clear error_code on entry in win32_unicode_path constructor#3056

Open
ssam18 wants to merge 3 commits intoboostorg:developfrom
ssam18:fix-win32-unicode-path-ec-clear
Open

Clear error_code on entry in win32_unicode_path constructor#3056
ssam18 wants to merge 3 commits intoboostorg:developfrom
ssam18:fix-win32-unicode-path-ec-clear

Conversation

@ssam18
Copy link
Copy Markdown

@ssam18 ssam18 commented Nov 12, 2025

Fixes #3035

Issue

The win32_unicode_path constructor accepts an error_code& parameter but wasn't clearing it on successful path conversion. This led to callers retaining stale error values even when operations succeeded.

Problem

As reported in #3035, when using file.open() with a pre-set error code (e.g., initialized to error::not_found as a default), the error would persist even after successful file operations. This is inconsistent with std::filesystem conventions where error_code parameters are cleared on success.

Solution

Added ec = {}; at the beginning of the constructor to ensure the error_code is always in a known state - either cleared for success or properly set for failure.

This aligns with:

  • The std::filesystem API convention (e.g., std::filesystem::create_directory)
  • The recommendation from @vinniefalco to clear ec immediately upon entry to avoid these kinds of issues
  • Beast's own file_win32::open which already clears ec on line 222

Testing

Windows-specific change. The fix is minimal and follows established error handling patterns in the codebase.

The win32_unicode_path constructor takes an error_code& parameter but
did not clear it on successful path conversion. This left callers with
stale error values even when the operation succeeded.

This is inconsistent with the std::filesystem convention where error_code
parameters are cleared on success (e.g., std::filesystem::create_directory).
It also caused unexpected behavior in file_win32::open() where a default
error_code value set before try/catch would persist even after successful
file operations.

This change adds 'ec = {};' at the beginning of the constructor to ensure
the error_code is always in a known state, either cleared for success or
set for failure.

Fixes boostorg#3035
@ssam18
Copy link
Copy Markdown
Author

ssam18 commented Nov 30, 2025

@vinniefalco - Can you please get a chance to review this PR?

@ashtum
Copy link
Copy Markdown
Collaborator

ashtum commented Nov 30, 2025

Please review all file-related operations to ensure they clear ec on success, and also determine how we can add appropriate tests to confirm this.

ssam18 added 2 commits April 1, 2026 20:40
Address review feedback and ensured all file-related operations
clear error_code on success.
libs/regex depends on libs/static_assert via Boost.Build, but it was
missing from the Windows CI submodule checkout, causing all MSVC builds
to fail with 'could not resolve project reference /boost/static_assert'.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.14%. Comparing base (0620a68) to head (ed41efe).
⚠️ Report is 10 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3056      +/-   ##
===========================================
- Coverage    93.18%   93.14%   -0.04%     
===========================================
  Files          176      177       +1     
  Lines        13703    13706       +3     
===========================================
- Hits         12769    12767       -2     
- Misses         934      939       +5     
Files with missing lines Coverage Δ
include/boost/beast/core/impl/file_posix.ipp 84.31% <100.00%> (-0.56%) ⬇️
include/boost/beast/core/impl/file_stdio.ipp 85.15% <100.00%> (+0.11%) ⬆️

... and 43 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0620a68...ed41efe. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

win32_unicode_path fails to clear ec.

2 participants