summaryrefslogtreecommitdiff
path: root/support/lib
diff options
context:
space:
mode:
authorMichael Schwarz <michi.schwarz@gmail.com>2015-09-07 00:53:22 +0200
committerMichael Schwarz <michi.schwarz@gmail.com>2015-09-16 01:41:45 +0200
commit57c9e9dc906da0dd4b5d34faeec2feee392a8b9c (patch)
tree96dff37fc3d65979e6b85b91c342504e4ee801d2 /support/lib
parentab26e5a8d54de099315e2cf473ec52610a6e3a17 (diff)
downloadpogojig-57c9e9dc906da0dd4b5d34faeec2feee392a8b9c.tar.gz
pogojig-57c9e9dc906da0dd4b5d34faeec2feee392a8b9c.tar.bz2
pogojig-57c9e9dc906da0dd4b5d34faeec2feee392a8b9c.zip
Prevent Python stack trace when an external command failed.
This catches the OSError thrown by the subprocess module and wraps it so that in the end only an error message is printed, explaining which command failed.
Diffstat (limited to 'support/lib')
-rw-r--r--support/lib/util.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/support/lib/util.py b/support/lib/util.py
index 3a852f4..915e33c 100644
--- a/support/lib/util.py
+++ b/support/lib/util.py
@@ -2,7 +2,8 @@ import contextlib, subprocess, tempfile, shutil, re, os
class UserError(Exception):
- pass
+ def __init__(self, message, *args):
+ super(UserError, self).__init__(message.format(*args))
def rename_atomic(source_path, target_path):
@@ -43,11 +44,14 @@ def command(args, remove_env = [], set_env = { }):
for k, v in set_env.items():
env[k] = v
- process = subprocess.Popen(args, env = env)
- process.wait()
+ try:
+ process = subprocess.Popen(args, env = env)
+ process.wait()
+ except OSError as e:
+ raise UserError('Error running {}: {}', args[0], e)
if process.returncode:
- raise UserError('Command failed: {}'.format(' '.join(args)))
+ raise UserError('Command failed: {}', ' '.join(args))
def bash_escape_string(string):