◐ Shell
clean mode source ↗

use posix error messages under 127 by youknowone · Pull Request #6420 · RustPython/RustPython

Walkthrough

Adds platform-conditional message construction in ToPyException for std::io::Error: Windows attempts to use the C runtime strerror for POSIX errno (1–127) with fallbacks to self.to_string() or "Unknown error"; Unix uses strerror(errno) when available; other targets fall back to the original error string.

Changes

Cohort / File(s) Summary
IO errno message handling
crates/vm/src/stdlib/io.rs
Adds platform-conditional logic in ToPyException for std::io::Error. On Windows, attempts to build messages via the C runtime strerror for POSIX errno (1–127) and falls back to self.to_string() or "Unknown error"; on Unix uses strerror(errno) when available; other targets use the original string.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Inspect platform-specific FFI calls to the C runtime (strerror) and safety around pointers and encoding.
  • Verify correct errno range checks (1–127) and the "Unknown error" fallback logic on Windows.
  • Check conditional compilation for Unix, Windows, and other targets and run cross-platform tests where possible.

Possibly related PRs

  • WindowsError #6333 — Also modifies Windows-specific error handling and message construction for OSError/IO errors; related at the code-level for errno/winerror and strerror usage.

Poem

🐰 I nibble at C strings late at night,
Hopping through errno by dim moonlight,
On Windows I peek where strerror hides,
On Unix I listen where the old echo bides,
Carrots, crumbs, and clearer error sights 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'use posix error messages under 127' accurately describes the main change: implementing POSIX error message handling for errno values under 127 in the ToPyException implementation for std::io::Error.
✨ 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

📥 Commits

Reviewing files that changed from the base of the PR and between b093b19 and 786a65e.

⛔ Files ignored due to path filters (3)
  • Lib/test/test_argparse.py is excluded by !Lib/**
  • Lib/test/test_py_compile.py is excluded by !Lib/**
  • Lib/test/test_subprocess.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/vm/src/stdlib/io.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/vm/src/stdlib/io.rs

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.