Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 8981db6

Browse files
committed
started to handle pipe errors - not quite working yet
1 parent 4905fcf commit 8981db6

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

cli4/cli4.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,21 @@ def write_results(results, output):
205205
results = yaml.safe_dump(results)
206206
if output == 'ndjson':
207207
# NDJSON support seems like a hack. There has to be a better way
208-
writer = jsonlines.Writer(sys.stdout)
209-
writer.write_all(results)
210-
writer.close()
208+
try:
209+
writer = jsonlines.Writer(sys.stdout)
210+
writer.write_all(results)
211+
writer.close()
212+
except (BrokenPipeError, IOError):
213+
pass
211214
return
212215

213216
if results:
214-
sys.stdout.write(results)
215-
if not results.endswith('\n'):
216-
sys.stdout.write('\n')
217+
try:
218+
sys.stdout.write(results)
219+
if not results.endswith('\n'):
220+
sys.stdout.write('\n')
221+
except (BrokenPipeError, IOError):
222+
pass
217223

218224
def do_it(args):
219225
"""Cloudflare API via command line"""

0 commit comments

Comments
 (0)