Use new_os_subtype_error for termios error construction

- Replace manual exception creation with new_os_subtype_error in termios
- Remove redundant .to_owned() calls in os.link() error messages
This commit is contained in:
Jeong, YunWon committed 2026-02-02 01:54:58 +09:00
1 parent 24b6f48841
commit 188d438e00
2 files changed
+7 -8

No files matched your search

+4 -5
View File
@@ -261,13 +261,12 @@ mod termios {
}
fn termios_error(err: std::io::Error, vm: &VirtualMachine) -> PyBaseExceptionRef {
vm.new_exception(
vm.new_os_subtype_error(
error_type(vm),
vec![
err.posix_errno().to_pyobject(vm),
vm.ctx.new_str(err.to_string()).into(),
],
Some(err.posix_errno()),
vm.ctx.new_str(err.to_string()),
)
.upcast()
}
#[pyattr(name = "error", once)]
+3 -3
View File
@@ -1278,9 +1278,9 @@ pub(super) mod _os {
{
use std::os::unix::ffi::OsStrExt;
let src_cstr = std::ffi::CString::new(src.path.as_os_str().as_bytes())
.map_err(|_| vm.new_value_error("embedded null byte".to_owned()))?;
.map_err(|_| vm.new_value_error("embedded null byte"))?;
let dst_cstr = std::ffi::CString::new(dst.path.as_os_str().as_bytes())
.map_err(|_| vm.new_value_error("embedded null byte".to_owned()))?;
.map_err(|_| vm.new_value_error("embedded null byte"))?;
let flags = if follow_symlinks.0 {
libc::AT_SYMLINK_FOLLOW
@@ -1315,7 +1315,7 @@ pub(super) mod _os {
// or raise NotImplementedError if explicitly set to False
if !follow_symlinks.0 {
return Err(vm.new_not_implemented_error(
"link: follow_symlinks unavailable on this platform".to_owned(),
"link: follow_symlinks unavailable on this platform",
));
}