Skip to content

Commit

Permalink
pipes: stop printing an error when pipes close
Browse files Browse the repository at this point in the history
Fixes #156
  • Loading branch information
jeffkaufman committed Feb 4, 2019
1 parent 5d0fbfa commit 503fa94
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions icdiff
Expand Up @@ -736,3 +736,8 @@ if __name__ == "__main__":
pass
else:
raise
# Close stderr to prevent printing errors when icdiff is piped to
# something that closes before icdiff is done writing
#
# See: https://stackoverflow.com/questions/26692284/how-to-prevent-brokenpipeerror-when-doing-a-flush-in-python
sys.stderr.close()
6 changes: 6 additions & 0 deletions test.sh
Expand Up @@ -121,6 +121,12 @@ check_gold gold-subcolors-bad-cat tests/input-{1,2}.txt --cols=80 --color-map='c
check_gold gold-subcolors-bad-fmt tests/input-{1,2}.txt --cols=80 --color-map='change:magenta:gold,description:cyan_bold'
check_gold gold-bad-encoding.txt tests/input-{1,2}.txt --encoding=nonexistend_encoding

# Testing pipe behavior doesn't fit well with the check_gold system
$INVOCATION tests/input-{4,5}.txt 2>/tmp/icdiff-pipe-error-output | head -n 1
if [ -s /tmp/icdiff-pipe-error-output ]; then
echo 'emitting errors on early pipe closure'
fail
fi

VERSION=$($INVOCATION --version | awk '{print $NF}')
if [ "$VERSION" != $(head -n 1 ChangeLog) ]; then
Expand Down

0 comments on commit 503fa94

Please sign in to comment.