diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index bb76f2dba..7f84b1972 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -1424,8 +1424,6 @@ class PosixTester(unittest.TestCase): # http://lists.freebsd.org/pipermail/freebsd-amd64/2012-January/014332.html raise unittest.SkipTest("OSError raised!") - # TODO: RUSTPYTHON: AssertionError: "'doesnotexistfilename' -> 'noodly2'" not found in "(2, 'No such file or directory (os error 2)')" - @unittest.expectedFailure def test_path_error2(self): """ Test functions that call path_error2(), providing two filenames in their exceptions. diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 49e28c049..77a021855 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -342,8 +342,6 @@ class CommonReadTest(ReadTest): finally: tar.close() - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_non_existent_tarfile(self): # Test for issue11513: prevent non-existent gzipped tarfiles raising # multiple exceptions. diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index 6695aea4c..05e7f59c7 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -862,13 +862,28 @@ fn key_error_str(exc: PyBaseExceptionRef, vm: &VirtualMachine) -> PyStrRef { fn os_error_str(exc: PyBaseExceptionRef, vm: &VirtualMachine) -> PyResult { let args = exc.args(); + let obj = exc.as_object().to_owned(); + if args.as_slice().len() == 2 { // SAFETY: len() == 2 is checked so get_arg 1 or 2 won't panic - let s = format!( - "[Errno {}] {}", - exc.get_arg(0).unwrap().str(vm)?, - exc.get_arg(1).unwrap().str(vm)? - ); + let errno = exc.get_arg(0).unwrap().str(vm)?; + let msg = exc.get_arg(1).unwrap().str(vm)?; + + let s = match obj.clone().get_attr("filename", vm) { + Ok(filename) => match obj.get_attr("filename2", vm) { + Ok(filename2) => format!( + "[Errno {}] {}: '{}' -> '{}'", + errno, + msg, + filename.str(vm)?, + filename2.str(vm)? + ), + Err(_) => format!("[Errno {}] {}: '{}'", errno, msg, filename.str(vm)?), + }, + Err(_) => { + format!("[Errno {}] {}", errno, msg) + } + }; Ok(vm.ctx.new_str(s)) } else { Ok(exc.str(vm))