diff --git a/vm/src/stdlib/nt.rs b/vm/src/stdlib/nt.rs index 9fa69291f..1b2dd55e9 100644 --- a/vm/src/stdlib/nt.rs +++ b/vm/src/stdlib/nt.rs @@ -16,8 +16,7 @@ pub(crate) mod module { builtins::{PyDictRef, PyStrRef, PyTupleRef}, common::{crt_fd::Fd, os::last_os_error, suppress_iph}, convert::ToPyException, - function::Either, - function::OptionalArg, + function::{Either, OptionalArg}, ospath::OsPath, stdlib::os::{errno_err, DirFd, FollowSymlinks, SupportFunc, TargetIsDirectory, _os}, PyResult, TryFromObject, VirtualMachine, diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index 040429e8e..bb2f6808e 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -407,7 +407,7 @@ pub(super) mod _os { return Err(vm.new_value_error("embedded null byte".to_string())); } if key.is_empty() || key.contains('=') { - return Err(vm.new_value_error("illegal environment variable name".to_string())); + return Err(vm.new_errno_error(22, "Invalid argument".to_owned())); } env::remove_var(key); Ok(()) diff --git a/vm/src/vm/vm_new.rs b/vm/src/vm/vm_new.rs index 922c137a0..4677d196f 100644 --- a/vm/src/vm/vm_new.rs +++ b/vm/src/vm/vm_new.rs @@ -189,6 +189,15 @@ impl VirtualMachine { self.new_exception_msg(os_error, msg) } + pub fn new_errno_error(&self, errno: i32, msg: String) -> PyBaseExceptionRef { + let vm = self; + let exc_type = + crate::exceptions::errno_to_exc_type(errno, vm).unwrap_or(vm.ctx.exceptions.os_error); + + let errno_obj = vm.new_pyobj(errno); + vm.new_exception(exc_type.to_owned(), vec![errno_obj, vm.new_pyobj(msg)]) + } + pub fn new_system_error(&self, msg: String) -> PyBaseExceptionRef { let sys_error = self.ctx.exceptions.system_error.to_owned(); self.new_exception_msg(sys_error, msg)