Skip to content

Give the Windows IO backend the error messages its siblings have - #3509

Open
dylanpulver wants to merge 5 commits into
python-trio:mainfrom
dylanpulver:fix/windows-io-error-messages
Open

dylanpulver wants to merge 5 commits into
python-trio:mainfrom
dylanpulver:fix/windows-io-error-messages

Conversation

@dylanpulver

@dylanpulver dylanpulver commented Sep 10, 2026 •

Copy link
Copy Markdown

On Windows, wait_readable / wait_writable raise BusyResourceError with no message and notify_closing raises ClosedResourceError with no message. The epoll and kqueue backends pass text for both, and _io_windows.py passes text for the lpOverlapped case in the same file.

I used "socket" rather than epoll's "fd", since _afd_poll and notify_closing resolve their argument through _get_base_socket. Happy to make them character-identical to the epoll strings instead.

The tests assert the message through pytest.raises(..., match=r"\S") rather than through the text, because the wording differs per backend. Stripping the three messages from _io_kqueue.py fails 12 of the 29 tests in test_io.py.

I'm on macOS, so the Windows suite is unrun here.

🤖 Generated with Claude Code

https://claude.ai/code/session_011M5uTyCU4WcNTsPvGrErDo

dylanpulver and others added 2 commits September 10, 2026 09:21
wait_readable / wait_writable raised a bare BusyResourceError, and
notify_closing a bare ClosedResourceError. The epoll and kqueue backends
describe both. _io_windows already passes a message for the lpOverlapped
case, so it was inconsistent with itself too.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011M5uTyCU4WcNTsPvGrErDo
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011M5uTyCU4WcNTsPvGrErDo
@codecov

codecov Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00000%. Comparing base (a3d7cdd) to head (02d0adf).
⚠️ Report is 46 commits behind head on main.

Additional details and impacted files
@@               Coverage Diff               @@
##                 main        #3509   +/-   ##
===============================================
  Coverage   100.00000%   100.00000%           
===============================================
  Files             128          128           
  Lines           19454        19551   +97     
  Branches         1321         1330    +9     
===============================================
+ Hits            19454        19551   +97     
Files with missing lines Coverage Δ
src/trio/_core/_io_windows.py 100.00000% <100.00000%> (ø)
src/trio/_core/_tests/test_io.py 100.00000% <100.00000%> (ø)

... and 17 files with indirect coverage changes

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

@A5rocks

A5rocks commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

BTW for future contributions I think you should avoid LLM generated PR descriptions. If you have nothing to say, that's fine. (though I appreciate the acknowledgement that Claude helped write this)

@A5rocks A5rocks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both these errors have coverage I assume, but no tests changed? Are the tests just not checking the message? Could you update the tests too?

These tests only checked the exception type, which is why the empty
Windows BusyResourceError and ClosedResourceError went unnoticed. The
messages differ per backend, so the assertion is that there is one.
Stripping the messages from the kqueue backend fails 12 of these tests.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011M5uTyCU4WcNTsPvGrErDo
Comment thread src/trio/_core/_tests/test_io.py Outdated
with pytest.raises(_core.BusyResourceError):
with pytest.raises(_core.BusyResourceError) as busy:
await wait_readable(a)
assert str(busy.value), "the error should say why the resource is busy"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use pytest's match argument instead

Same assertion, the idiom the reviewer asked for. Stripping the messages
from the kqueue backend still fails 12 of these tests.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011M5uTyCU4WcNTsPvGrErDo
@dylanpulver

Copy link
Copy Markdown
Author

Both points are in, pushed on 23 Sept. I should have said so at the time rather than leaving this sitting.

@A5rocks the tests now check the message, not just the type. @CoolCat467 that check is pytest.raises(..., match=...), with the pattern r"\S" instead of the text, because the wording differs per backend.

Stripping the three messages out of _io_kqueue.py fails 12 of the 29 tests in test_io.py, and all 29 pass with them in place.

I also cut the description down.

@CoolCat467

Copy link
Copy Markdown
Member

Still kind of wish message matching was there but fine I guess

Taking the review point. `match=r"\S"` only asserted a message existed, so
rewording one would not have been noticed.

`ClosedResourceError` is the same sentence on all three backends up to the last
word, so the test matches "another task closed this " directly.

`BusyResourceError` has two unrelated texts: epoll and windows say "another
task is already reading / writing this ...", kqueue says "attempt to register
multiple listeners for same ident/filter pair". BUSY_MESSAGE matches either, so
the assertion is that the message is one of the two real ones.

Rewording kqueue's two messages while keeping them non-empty now fails 12 of the
29 tests in test_io.py. The same rewording passed all 29 under `r"\S"`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011M5uTyCU4WcNTsPvGrErDo
@dylanpulver

Copy link
Copy Markdown
Author

Message matching is in.

ClosedResourceError is the same sentence on all three backends up to the last word, so the test matches "another task closed this " directly.

BusyResourceError has two unrelated texts. epoll and windows say "another task is already reading / writing this ...", kqueue says "attempt to register multiple listeners for same ident/filter pair". So:

BUSY_MESSAGE = r"already reading / writing this|multiple listeners for same ident"

which asserts the message is one of the two real ones rather than just non-empty.

The difference it makes, rewording kqueue's two messages while keeping them non-empty:

with match=r"\S"      29 passed
with the real texts   12 failed, 17 passed

That is the gap you were pointing at. 29 pass unchanged, and ruff check and ruff format are clean.

@dylanpulver dylanpulver moved this to In Progress in OSS contributions pipeline Nov 7, 2026
@CoolCat467 CoolCat467 added the LLM Slop Entirely generated by a large language model with little or no human oversight label Nov 10, 2026

This branch has not been deployed

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

Labels

LLM Slop Entirely generated by a large language model with little or no human oversight

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants