Skip to content

Commit

Permalink
improve error handling robustness for os.execvpe
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpetrello committed Jul 2, 2018
1 parent 5436e55 commit 3399dd7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ptyprocess/ptyprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,14 @@ def spawn(
os.execv(command, argv)
else:
os.execvpe(command, argv, env)
except OSError as err:
except Exception as err:
# [issue #119] 5. If exec fails, the child writes the error
# code back to the parent using the pipe, then exits.
tosend = 'OSError:{}:{}'.format(err.errno, str(err))
if isinstance(err, OSError):
tosend = 'OSError:{}:{}'.format(err.errno, str(err))
else:
cls_name = err.__class__.__name__
tosend = 'Exception:0:{}: {}'.format(cls_name, str(err))
if PY3:
tosend = tosend.encode('utf-8')
os.write(exec_err_pipe_write, tosend)
Expand Down

0 comments on commit 3399dd7

Please sign in to comment.