Skip to content

Commit 73870bf

Browse files
ZackerySpytzbenjaminp
authored andcommitted
closes bpo-32490: Fix filename duplication in subprocess exception message. (GH-9163)
8621bb5 sets the filename in directly in the FileNotFoundError, so we may revert the earlier fix 5f78040.
1 parent 3102e24 commit 73870bf

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

Lib/subprocess.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,8 +1512,6 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
15121512
err_filename = orig_executable
15131513
if errno_num != 0:
15141514
err_msg = os.strerror(errno_num)
1515-
if errno_num == errno.ENOENT:
1516-
err_msg += ': ' + repr(err_filename)
15171515
raise child_exception_type(errno_num, err_msg, err_filename)
15181516
raise child_exception_type(err_msg)
15191517

Lib/test/test_subprocess.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,6 @@ def _get_chdir_exception(self):
15201520
# string and instead capture the exception that we want to see
15211521
# below for comparison.
15221522
desired_exception = e
1523-
desired_exception.strerror += ': ' + repr(self._nonexistent_dir)
15241523
else:
15251524
self.fail("chdir to nonexistent directory %s succeeded." %
15261525
self._nonexistent_dir)
@@ -1537,6 +1536,7 @@ def test_exception_cwd(self):
15371536
# it up to the parent process as the correct exception.
15381537
self.assertEqual(desired_exception.errno, e.errno)
15391538
self.assertEqual(desired_exception.strerror, e.strerror)
1539+
self.assertEqual(desired_exception.filename, e.filename)
15401540
else:
15411541
self.fail("Expected OSError: %s" % desired_exception)
15421542

@@ -1551,6 +1551,7 @@ def test_exception_bad_executable(self):
15511551
# it up to the parent process as the correct exception.
15521552
self.assertEqual(desired_exception.errno, e.errno)
15531553
self.assertEqual(desired_exception.strerror, e.strerror)
1554+
self.assertEqual(desired_exception.filename, e.filename)
15541555
else:
15551556
self.fail("Expected OSError: %s" % desired_exception)
15561557

@@ -1564,6 +1565,7 @@ def test_exception_bad_args_0(self):
15641565
# it up to the parent process as the correct exception.
15651566
self.assertEqual(desired_exception.errno, e.errno)
15661567
self.assertEqual(desired_exception.strerror, e.strerror)
1568+
self.assertEqual(desired_exception.filename, e.filename)
15671569
else:
15681570
self.fail("Expected OSError: %s" % desired_exception)
15691571

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Prevent filename duplication in :mod:`subprocess` exception messages. Patch
2+
by Zackery Spytz.

0 commit comments

Comments
 (0)