beast icon indicating copy to clipboard operation
beast copied to clipboard

Clear error_code on entry in win32_unicode_path constructor

Open ssam18 opened this issue 2 months ago • 2 comments

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.

ssam18 avatar Nov 12 '25 20:11 ssam18

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

ssam18 avatar Nov 30 '25 14:11 ssam18

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.

ashtum avatar Nov 30 '25 15:11 ashtum