Skip to content

Commit

Permalink
Fix error printing to stderr char by char (DataDog#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Bouchare committed Oct 25, 2019
1 parent 0844926 commit 1711c99
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions datadog/dogshell/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,31 @@

def print_err(msg):
if is_p3k():
print('ERROR: ' + msg + '\n', file=sys.stderr)
print(msg + '\n', file=sys.stderr)
else:
sys.stderr.write(msg + '\n')


def report_errors(res):
if 'errors' in res:
for e in res['errors']:
print_err('ERROR: ' + e)
errors = res['errors']
if isinstance(errors, list):
for error in errors:
print_err("ERROR: {}".format(error))
else:
print_err("ERROR: {}".format(errors))
sys.exit(1)
return False


def report_warnings(res):
if 'warnings' in res:
for e in res['warnings']:
print_err('WARNING: ' + e)
warnings = res['warnings']
if isinstance(warnings, list):
for warning in warnings:
print_err("WARNING: {}".format(warning))
else:
print_err("WARNING: {}".format(warnings))
return True
return False

Expand Down

0 comments on commit 1711c99

Please sign in to comment.