Skip to content

Commit eaa3201

Browse files
committed
Merge pull request #2831 from ddunbar/improve-shell-diagnostics
[utils] Improve swift_build_support.shell failure messages.
2 parents a995362 + 01a1559 commit eaa3201

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

utils/swift_build_support/swift_build_support/shell.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import sys
2323
from contextlib import contextmanager
2424

25+
from . import diagnostics
26+
2527
dry_run = False
2628

2729

@@ -66,7 +68,16 @@ def call(command, stderr=None, env=None, dry_run=None):
6668
if env is not None:
6769
_env = dict(os.environ)
6870
_env.update(env)
69-
subprocess.check_call(command, env=_env, stderr=stderr)
71+
try:
72+
subprocess.check_call(command, env=_env, stderr=stderr)
73+
except subprocess.CalledProcessError as e:
74+
diagnostics.fatal(
75+
"command terminated with a non-zero exit status " +
76+
str(e.returncode) + ", aborting")
77+
except OSError as e:
78+
diagnostics.fatal(
79+
"could not execute '" + quote_command(command) +
80+
"': " + e.strerror)
7081

7182

7283
@contextmanager

utils/swift_build_support/tests/test_tar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_tar_this_file_succeeds(self):
5151
expect.format(dest=destination, source=source))
5252

5353
def test_tar_nonexistent_file_raises(self):
54-
with self.assertRaises(subprocess.CalledProcessError):
54+
with self.assertRaises(SystemExit):
5555
tar(source='/path/to/something/that/surely/doesnt/exist',
5656
destination='/another/path/that/shouldnt/exist')
5757

0 commit comments

Comments
 (0)