Skip to content

Commit 3399dd7

Browse files
committed
improve error handling robustness for os.execvpe
see: pexpect/pexpect#512
1 parent 5436e55 commit 3399dd7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ptyprocess/ptyprocess.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,14 @@ def spawn(
283283
os.execv(command, argv)
284284
else:
285285
os.execvpe(command, argv, env)
286-
except OSError as err:
286+
except Exception as err:
287287
# [issue #119] 5. If exec fails, the child writes the error
288288
# code back to the parent using the pipe, then exits.
289-
tosend = 'OSError:{}:{}'.format(err.errno, str(err))
289+
if isinstance(err, OSError):
290+
tosend = 'OSError:{}:{}'.format(err.errno, str(err))
291+
else:
292+
cls_name = err.__class__.__name__
293+
tosend = 'Exception:0:{}: {}'.format(cls_name, str(err))
290294
if PY3:
291295
tosend = tosend.encode('utf-8')
292296
os.write(exec_err_pipe_write, tosend)

0 commit comments

Comments
 (0)