GeezerVison is showing github.com — enhance error codec and exit code by youknowone · Pull Request #6602 · RustPython/RustPython
Conversation
youknowone
commented
Dec 31, 2025
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
support #6428
Summary by CodeRabbit
Release Notes
- Bug Fixes
- Improved stderr output handling to gracefully manage non-ASCII characters in error messages
- Enhanced integer-to-code conversion with better fallback mechanisms for edge cases
- Fixed exception printing to properly leverage Python's error handling system
✏️ Tip: You can customize this high-level summary in your review settings.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Dec 31, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
📝 Walkthrough
Walkthrough
The PR modifies the VM's error and IO handling in three areas: setting "backslashreplace" error handler for stderr in TextIOWrapper, implementing fallback logic for PyInt-to-code conversion to handle overflow cases, and redirecting exception printing through Python's sys.stderr.write() method instead of direct writes.
Changes
| Cohort / File(s) |
Summary |
Python IO and Exception Handling crates/vm/src/vm/mod.rs |
Modified TextIOWrapper creation to apply "backslashreplace" error handler for stderr (fd == 2); changed exception printing to use sys.stderr.write() instead of direct PyStderr writes; updated PyInt-to-code conversion with fallback logic (try to_u32, then to_i32 with cast, default to -1 on overflow) |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
🐰 A rabbit hops through stderr streams so fine,
With backslash-replace and write-calls divine,
Integer conversions now gracefully fall,
Python's own write method handles it all! ✨
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 mentions 'error codec' and 'exit code', which relate to the error handling changes in the PR, but doesn't clearly highlight the main changes like Python IO redirection, error handler propagation, or stderr output handling. |
✨ Finishing touches
📜 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 cd012f9 and 8cf8029.
📒 Files selected for processing (1)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by running cargo fmt to format Rust code
Always run clippy to lint 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:
🧬 Code graph analysis (1)
crates/vm/src/vm/mod.rs (4)
crates/vm/src/stdlib/io.rs (2)
errors (836-838)
errors (3107-3109)
crates/vm/src/builtins/int.rs (1)
crates/codegen/src/compile.rs (2)
to_u32 (6075-6075)
to_u32 (6079-6081)
crates/vm/src/stdlib/sys.rs (1)
🔇 Additional comments (3)
crates/vm/src/vm/mod.rs (3)
330-340: LGTM! Proper stderr error handler configuration.
The code correctly sets "backslashreplace" as the error handler for stderr (fd == 2), ensuring that unencodable characters are escaped rather than causing encoding errors. This aligns with CPython's default stderr behavior and properly integrates with the TextIOWrapper constructor call.
881-885: LGTM! Proper use of Python's stderr write method.
Writing through sys.stderr.write() correctly engages the backslashreplace error handler configured at lines 330-335. The use of let _ = to ignore write errors is appropriate here—if stderr itself fails, there's no alternative output mechanism available in this exception handling context.
862-868: Improved overflow handling for exit codes.
The fallback logic properly handles various integer representations:
- Positive values via
to_u32()
- Negative values via
to_i32() with cast to preserve two's complement
- Overflow cases default to
-1 (represented as 4294967295 in u32)
This prevents panics from the previous unwrap() approach. The overflow default of -1 aligns with observed CPython behavior for very large integers in SystemExit; on POSIX systems, only the low 8 bits are used by shells anyway (making -1 resolve to 255, a semantically reasonable error code).
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|