diff --git a/spawn.py b/spawn.py index aad277b0..0d1bd039 100644 --- a/spawn.py +++ b/spawn.py @@ -71,9 +71,15 @@ def spawn(cmd, search_path=1, verbose=0, dry_run=0): env = dict(os.environ, MACOSX_DEPLOYMENT_TARGET=cur_target) - proc = subprocess.Popen(cmd, env=env) - proc.wait() - exitcode = proc.returncode + try: + proc = subprocess.Popen(cmd, env=env) + proc.wait() + exitcode = proc.returncode + except OSError as exc: + if not DEBUG: + cmd = cmd[0] + raise DistutilsExecError( + "command %r failed: %s" % (cmd, exc.args[-1])) from exc if exitcode: if not DEBUG: diff --git a/tests/test_spawn.py b/tests/test_spawn.py index 3647bab7..4ec767b1 100644 --- a/tests/test_spawn.py +++ b/tests/test_spawn.py @@ -124,6 +124,11 @@ def test_find_executable(self): rv = find_executable(program) self.assertEqual(rv, filename) + def test_spawn_missing_exe(self): + with self.assertRaises(DistutilsExecError) as ctx: + spawn(['does-not-exist']) + self.assertIn("command 'does-not-exist' failed", str(ctx.exception)) + def test_suite(): return unittest.makeSuite(SpawnTestCase)