diff options
author | W. Trevor King <wking@drexel.edu> | 2008-11-13 09:02:22 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2008-11-13 09:02:22 -0500 |
commit | e5460203573f54a74c06f1b0922dcbbb1076f64c (patch) | |
tree | 58719885a3803a6c497e3be09e7f0828debb62ff /libbe/arch.py | |
parent | 9055757a1b30c55798173f2454de8d4fa0676d40 (diff) | |
download | bugseverywhere-e5460203573f54a74c06f1b0922dcbbb1076f64c.tar.gz |
Catch OSErrors from Popen()s
From the subprocess module documentation:
http://www.python.org/doc/2.5.2/lib/node530.html
"The most common exception raised is OSError. This occurs, for example,
when trying to execute a non-existent file. Applications should prepare
for OSError exceptions."
And from the os module documentation:
http://www.python.org/doc/2.5.2/lib/module-os.html
"exception error
This exception is raised when a function returns a system-related
error (not for illegal argument types or other incidental
errors). This is also known as the built-in exception OSError. The
accompanying value is a pair containing the numeric error code
from errno and the corresponding string, as would be printed by
the C function perror(). See the module errno, which contains
names for the error codes defined by the underlying operating
system.
When exceptions are classes, this exception carries two
attributes, errno and strerror. The first holds the value of the C
errno variable, and the latter holds the corresponding error
message from strerror(). For exceptions that involve a file system
path (such as chdir() or unlink()), the exception instance will
contain a third attribute, filename, which is the file name passed
to the function."
I turned this up running be/test.py, when it defaulted to the tla client
which I didn't have installed. I don't have things working yet, so I
can't create a bug at the moment...
Diffstat (limited to 'libbe/arch.py')
-rw-r--r-- | libbe/arch.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/libbe/arch.py b/libbe/arch.py index 624aea3..038325a 100644 --- a/libbe/arch.py +++ b/libbe/arch.py @@ -24,7 +24,11 @@ if client is None: config.set_val("arch_client", client) def invoke(args): - q = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) + try : + q = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) + except OSError, e : + strerror = "%s\nwhile executing %s" % (e.args[1], args) + raise Exception("Command failed: %s" % strerror) output = q.stdout.read() error = q.stderr.read() status = q.wait() |