-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Handle OsError in REPL #6187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle OsError in REPL #6187
Conversation
WalkthroughIntroduces a Unix-specific ReadlineResult::OsError variant and integrates handling across readline, the REPL loop, and the builtin input function. On Unix, OS-level readline errors are propagated as OS error exceptions; the REPL prints the error and exits the loop. Existing branches remain unchanged. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User
participant RL as Readline (Unix)
participant VM as VM
participant SH as REPL Shell
rect rgba(230,240,255,0.6)
U->>SH: Enter input
SH->>RL: read_line()
RL-->>SH: OsError(errno)
note over SH: New Unix-specific branch
SH->>VM: new_os_error(errno)
VM-->>SH: OSError instance
SH-->>U: Print error
SH-->>U: Exit REPL loop
end
sequenceDiagram
autonumber
participant U as User code
participant RL as Readline (Unix)
participant VM as VM
participant BI as builtin input()
rect rgba(230,255,230,0.6)
U->>BI: input()
BI->>RL: read_line()
RL-->>BI: OsError(errno)
note over BI: New Unix-specific arm
BI->>VM: new_os_error(errno.to_string())
VM-->>BI: OSError
BI-->>U: Raise OSError
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/shell.rs (1)
212-218: Usevm.new_os_error()for consistency.For consistency with the handling in
builtins.rs(line 493) and cleaner error messages, consider usingvm.new_os_error(num.to_string())instead of manually constructing the exception.Apply this diff:
- #[cfg(unix)] - ReadlineResult::OsError(num) => { - let os_error = - vm.new_exception_msg(vm.ctx.exceptions.os_error.to_owned(), format!("{num:?}")); - vm.print_exception(os_error); - break; - } + #[cfg(unix)] + ReadlineResult::OsError(num) => { + let os_error = vm.new_os_error(num.to_string()); + vm.print_exception(os_error); + break; + }
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/shell.rs(1 hunks)vm/src/readline.rs(2 hunks)vm/src/stdlib/builtins.rs(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Format Rust code with the default rustfmt style (runcargo fmt)
Run clippy and fix any warnings or lints introduced by your changes
Follow Rust best practices for error handling and memory management
Files:
vm/src/readline.rssrc/shell.rsvm/src/stdlib/builtins.rs
{vm,stdlib}/**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use RustPython macros (
pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
vm/src/readline.rsvm/src/stdlib/builtins.rs
🔇 Additional comments (3)
vm/src/readline.rs (2)
16-17: LGTM!The Unix-specific
OsErrorvariant is properly gated and provides a clean way to propagate OS-level readline errors (such as EBADF when stdout is closed).
123-124: LGTM!The mapping from
ReadlineError::ErrnotoReadlineResult::OsErrorcorrectly propagates Unix-specific errno errors through the readline interface.vm/src/stdlib/builtins.rs (1)
492-493: LGTM!The Unix-specific error handling correctly converts readline OS errors into Python OSError exceptions using the idiomatic
vm.new_os_error()method.
youknowone
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing!
Closes #6146
Summary by CodeRabbit