Skip to content

Commit

Permalink
started to handle pipe errors - not quite working yet
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtin committed Jan 18, 2020
1 parent 4905fcf commit 8981db6
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cli4/cli4.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,21 @@ def write_results(results, output):
results = yaml.safe_dump(results)
if output == 'ndjson':
# NDJSON support seems like a hack. There has to be a better way
writer = jsonlines.Writer(sys.stdout)
writer.write_all(results)
writer.close()
try:
writer = jsonlines.Writer(sys.stdout)
writer.write_all(results)
writer.close()
except (BrokenPipeError, IOError):
pass
return

if results:
sys.stdout.write(results)
if not results.endswith('\n'):
sys.stdout.write('\n')
try:
sys.stdout.write(results)
if not results.endswith('\n'):
sys.stdout.write('\n')
except (BrokenPipeError, IOError):
pass

def do_it(args):
"""Cloudflare API via command line"""
Expand Down

0 comments on commit 8981db6

Please sign in to comment.