Skip to content

Commit

Permalink
git-pw: Gracefully handle filters closing the stdout pipe
Browse files Browse the repository at this point in the history
When piping git pw through a pipe to a filter, the filter may close its
stdin early (for instance git pw list -j | head) and the next write to
stdout from git pw will raise an exception:

Traceback (most recent call last):
  File "/home/damien/.local/bin/git-pw", line 912, in <module>
    ret = git_pw.run()
  File "/home/damien/.local/bin/git-pw", line 756, in run
    ret = getattr(self, method)()
  File "/home/damien/.local/bin/git-pw", line 653, in do_list
    print(json.dumps(series))
IOError: [Errno 32] Broken pipe

We do want to play nice with those filters too, to just catch that
IOError with errno set to EPIPE and exit without complaining.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
  • Loading branch information
Damien Lespiau committed Feb 9, 2016
1 parent 3e560e2 commit de98bb7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions git-pw/git-pw
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import argparse
from collections import OrderedDict
import errno
import fcntl
import json
import os
Expand Down Expand Up @@ -753,9 +754,14 @@ class GitPatchwork(object):
def run(self):
self.setup()
method = 'do_' + self.cmd.method_name()
ret = getattr(self, method)()
ret = 0 if ret is None else ret
return ret
try:
ret = getattr(self, method)()
ret = 0 if ret is None else ret
return ret
except IOError as e:
if e.errno != errno.EPIPE:
raise
return 0


class AliasedSubParsersAction(argparse._SubParsersAction):
Expand Down

0 comments on commit de98bb7

Please sign in to comment.