From a0abcac6e0edbacac1ebb51c2237ca0e7a0b9b38 Mon Sep 17 00:00:00 2001 From: Jeff Yates Date: Sun, 22 Nov 2020 15:37:03 -0500 Subject: [PATCH] error handling for writing json --- sorter.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sorter.rb b/sorter.rb index cac6539..da99f3b 100755 --- a/sorter.rb +++ b/sorter.rb @@ -47,10 +47,13 @@ end # output - a hash containing all of our output #This method converts the output hash to JSON and writes it to "output.json" def write_output_json (output, filename) - pp output - outfile = File.open(filename,'w') - outfile.write(output.to_json) - outfile.close + begin + outfile = File.open(filename,'w') + outfile.write(output.to_json) + outfile.close + rescue + pp output + abort end def write_output_csv (output, filename)