WindowsError by youknowone · Pull Request #6333 · RustPython/RustPython
Walkthrough
Windows-specific updates: OSError initialization now converts a provided winerror to an errno and replaces the first arg on Windows; OSError stringification uses "WinError" when winerror is set and "Errno" otherwise; WindowsError is exported as an alias to OSError only on Windows builds. (50 words)
Changes
| Cohort / File(s) | Summary |
|---|---|
Windows OSError Exception Handling crates/vm/src/exceptions.rs |
On Windows, slot_init converts a provided winerror to an errno and replaces args[0] with that errno. __str__ now chooses label/code as ("WinError", code) when winerror is set, otherwise ("Errno", errno), and formats output as "[{label} {code}] ...". |
Windows Error Alias Export crates/vm/src/stdlib/builtins.rs |
Added WindowsError as an alias to OSError in module initialization under #[cfg(windows)], exposing it only on Windows builds. |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~10 minutes
- Review
winerror→errnoconversion logic incrates/vm/src/exceptions.rsfor parity with CPython. - Verify
__str__formatting covers all argument/path variants and preserves existing non-Windows behavior. - Confirm
#[cfg(windows)]gating incrates/vm/src/stdlib/builtins.rsprevents exposure on non-Windows builds.
Poem
🐰 I hopped through errors, found their lore,
Turned WinError keys to errno's door,
Now strings proclaim what codes convey,
And WindowsError joins the play.
Rabbit cheers — bugs led astray! 🥕
Pre-merge checks and finishing touches
❌ Failed checks (1 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Title check | ❓ Inconclusive | The title 'WindowsError' is too vague and generic. While it relates to the changeset (adding WindowsError alias and Windows-specific error handling), it doesn't meaningfully summarize what the change accomplishes or why it matters. | Consider a more descriptive title that explains the purpose, such as 'Add WindowsError alias to builtins and improve Windows OSError handling' or 'Align Windows OSError behavior with CPython'. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✨ Finishing touches
- 📝 Generate docstrings
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
📜 Recent review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Lib/test/test_exception_hierarchy.pyis excluded by!Lib/**
📒 Files selected for processing (2)
crates/vm/src/exceptions.rs(2 hunks)crates/vm/src/stdlib/builtins.rs(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- crates/vm/src/exceptions.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint Rust code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
crates/vm/src/stdlib/builtins.rs
🧬 Code graph analysis (1)
crates/vm/src/stdlib/builtins.rs (1)
crates/vm/src/stdlib/os.rs (1)
extend_module(1573-1597)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run tests under miri
- GitHub Check: Check Rust code with clippy
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
🔇 Additional comments (1)
crates/vm/src/stdlib/builtins.rs (1)
1191-1195: Windows-onlyWindowsErroralias correctly mirrors CPython behaviorDefining
WindowsErroras a Windows-only alias toOSErrorviactx.exceptions.os_erroris consistent with CPython's builtins and fits well alongside the other OSError aliases. Before merging, ensurecargo fmtandcargo clippypass on this file per the Rust coding guidelines.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.