Handle OsError in REPL (#6187)

This commit is contained in:
Anton authored and GitHub committed 2025-10-13 10:18:51 +09:00
1 parent 7986fee56f
commit b56e469a5f
3 files changed
+13

No files matched your search

+7
View File
@@ -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;
+4
View File
@@ -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()),
};
}
+2
View File
@@ -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 {