mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 10:44:36 +08:00
Handle OsError in REPL (#6187)
This commit is contained in:
1 parent
7986fee56f
commit
b56e469a5f
3 files changed
+13
No files matched your search
@@ -209,6 +209,13 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
|
||||
ReadlineResult::Eof => {
|
||||
break;
|
||||
}
|
||||
#[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;
|
||||
}
|
||||
ReadlineResult::Other(err) => {
|
||||
eprintln!("Readline error: {err:?}");
|
||||
break;
|
||||
|
||||
@@ -13,6 +13,8 @@ pub enum ReadlineResult {
|
||||
Eof,
|
||||
Interrupt,
|
||||
Io(std::io::Error),
|
||||
#[cfg(unix)]
|
||||
OsError(nix::Error),
|
||||
Other(OtherError),
|
||||
}
|
||||
|
||||
@@ -118,6 +120,8 @@ mod rustyline_readline {
|
||||
Err(ReadlineError::Eof) => ReadlineResult::Eof,
|
||||
Err(ReadlineError::Io(e)) => ReadlineResult::Io(e),
|
||||
Err(ReadlineError::Signal(_)) => continue,
|
||||
#[cfg(unix)]
|
||||
Err(ReadlineError::Errno(num)) => ReadlineResult::OsError(num),
|
||||
Err(e) => ReadlineResult::Other(e.into()),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -489,6 +489,8 @@ mod builtins {
|
||||
Err(vm.new_exception_empty(vm.ctx.exceptions.keyboard_interrupt.to_owned()))
|
||||
}
|
||||
ReadlineResult::Io(e) => Err(vm.new_os_error(e.to_string())),
|
||||
#[cfg(unix)]
|
||||
ReadlineResult::OsError(num) => Err(vm.new_os_error(num.to_string())),
|
||||
ReadlineResult::Other(e) => Err(vm.new_runtime_error(e.to_string())),
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user