MCPcopy Index your code
hub / github.com/RustPython/RustPython / to_os_error_builder

Method to_os_error_builder

crates/vm/src/exceptions.rs:1382–1423  ·  view source on GitHub ↗
(&self, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1380
1381impl ToOSErrorBuilder for std::io::Error {
1382 fn to_os_error_builder(&self, vm: &VirtualMachine) -> OSErrorBuilder {
1383 use crate::common::os::ErrorExt;
1384
1385 let errno = self.posix_errno();
1386 #[cfg(windows)]
1387 let msg = 'msg: {
1388 // Use C runtime's strerror for POSIX errno values.
1389 // For Windows-specific error codes, fall back to FormatMessage.
1390 const MAX_POSIX_ERRNO: i32 = 127;
1391 if errno > 0 && errno <= MAX_POSIX_ERRNO {
1392 let ptr = unsafe { libc::strerror(errno) };
1393 if !ptr.is_null() {
1394 let s = unsafe { core::ffi::CStr::from_ptr(ptr) }.to_string_lossy();
1395 if !s.starts_with("Unknown error") {
1396 break 'msg s.into_owned();
1397 }
1398 }
1399 }
1400 self.to_string()
1401 };
1402 #[cfg(unix)]
1403 let msg = {
1404 let ptr = unsafe { libc::strerror(errno) };
1405 if !ptr.is_null() {
1406 unsafe { core::ffi::CStr::from_ptr(ptr) }
1407 .to_string_lossy()
1408 .into_owned()
1409 } else {
1410 self.to_string()
1411 }
1412 };
1413 #[cfg(not(any(windows, unix)))]
1414 let msg = self.to_string();
1415
1416 #[allow(unused_mut)]
1417 let mut builder = OSErrorBuilder::with_errno(errno, msg, vm);
1418 #[cfg(windows)]
1419 if let Some(winerror) = self.raw_os_error() {
1420 builder = builder.winerror(winerror.to_pyobject(vm));
1421 }
1422 builder
1423 }
1424}
1425
1426impl ToPyException for std::io::Error {

Callers 6

to_pyexceptionMethod · 0.80
with_filenameMethod · 0.80
symlinkFunction · 0.80
renameFunction · 0.80
linkFunction · 0.80

Calls 8

strerrorFunction · 0.85
posix_errnoMethod · 0.80
starts_withMethod · 0.80
into_ownedMethod · 0.80
to_stringMethod · 0.80
winerrorMethod · 0.80
to_string_lossyMethod · 0.45
to_pyobjectMethod · 0.45

Tested by

no test coverage detected