Skip to content

Commit b56e469

Browse files
authored
Handle OsError in REPL (RustPython#6187)
1 parent 7986fee commit b56e469

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/shell.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
209209
ReadlineResult::Eof => {
210210
break;
211211
}
212+
#[cfg(unix)]
213+
ReadlineResult::OsError(num) => {
214+
let os_error =
215+
vm.new_exception_msg(vm.ctx.exceptions.os_error.to_owned(), format!("{num:?}"));
216+
vm.print_exception(os_error);
217+
break;
218+
}
212219
ReadlineResult::Other(err) => {
213220
eprintln!("Readline error: {err:?}");
214221
break;

vm/src/readline.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pub enum ReadlineResult {
1313
Eof,
1414
Interrupt,
1515
Io(std::io::Error),
16+
#[cfg(unix)]
17+
OsError(nix::Error),
1618
Other(OtherError),
1719
}
1820

@@ -118,6 +120,8 @@ mod rustyline_readline {
118120
Err(ReadlineError::Eof) => ReadlineResult::Eof,
119121
Err(ReadlineError::Io(e)) => ReadlineResult::Io(e),
120122
Err(ReadlineError::Signal(_)) => continue,
123+
#[cfg(unix)]
124+
Err(ReadlineError::Errno(num)) => ReadlineResult::OsError(num),
121125
Err(e) => ReadlineResult::Other(e.into()),
122126
};
123127
}

vm/src/stdlib/builtins.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ mod builtins {
489489
Err(vm.new_exception_empty(vm.ctx.exceptions.keyboard_interrupt.to_owned()))
490490
}
491491
ReadlineResult::Io(e) => Err(vm.new_os_error(e.to_string())),
492+
#[cfg(unix)]
493+
ReadlineResult::OsError(num) => Err(vm.new_os_error(num.to_string())),
492494
ReadlineResult::Other(e) => Err(vm.new_runtime_error(e.to_string())),
493495
}
494496
} else {

0 commit comments

Comments
 (0)