Skip to content

Commit

Permalink
Don't fail on encode as json error.
Browse files Browse the repository at this point in the history
Instead print an error message with the record that failed
and continue.
  • Loading branch information
jasonish committed Jul 1, 2015
1 parent ad701c4 commit 67a0dbb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions idstools/scripts/u2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,16 @@ def main():
formatter = Formatter(msgmap=msgmap, classmap=classmap)

for record in reader:
as_json = json.dumps(formatter.format(record))
for out in outputs:
out.write(as_json)
if bookmark:
filename, offset = reader.tell()
bookmark.update(filename, offset)
try:
as_json = json.dumps(formatter.format(record))
for out in outputs:
out.write(as_json)
if bookmark:
filename, offset = reader.tell()
bookmark.update(filename, offset)
except Exception as err:
LOG.error("Failed to encode record as JSON: %s: %s" % (
str(err), str(record)))

if __name__ == "__main__":
sys.exit(main())

0 comments on commit 67a0dbb

Please sign in to comment.