Open dEhiN opened 5 days ago
Adding the 2 changes as tasks that can be checked off:
generate_default_startup_data
to call the existing function json_reader
for reading in any JSON file data, rather than using a try-except
block to do it directly.comp_start
app.Copy-pasting from commit 359aa2e:
While testing the changes made in the previous commit, it became apparent that if the default startup data JSON file was blank, the program would print out the appropriate error message but then would continue execution.
_This was because, while functions like json_reader
would return a boolean as one of the return values to indicate if the function was successful, both functions generate_default_startup_data
and generate_new_json_data
wouldn't return any boolean value._
Both functions were refactored to return a boolean value, which is then passed up the stack and accounted for in the main loop.
This was tested using a completely blank default startup data JSON file and the following is outputted, after which, execution returns to the main loop:
ERROR
The following error was encountered:
Function: generate_default_startup_data
Message: Unable to read startup data. Error information is below:
JSONDecodeError - Expecting value: line 1 column 1 (char 0)
There was a problem generating the startup data!
Please see the error details above.
Tested the following scenarios and confirmed the proper error handling occurs:
In all cases, a proper trail of error messages was printed out indicating, from highest function to lowest, each of errors along the way. The first error message, printed from the function json_reader
displayed the correct issue in each of the tests above
Created this issue while working on #20 because realized that currently the way the default startup data is handled can be refactored to be a little more efficient and forward-thinking via 2 changes:
generate_default_startup_data
in thedata_generate
module directly reads in the default startup data JSON file, which is called _defaultstartup.json. However, since there is thejson_reader
function in thejsonfn
module, there is no need for this. Additionally, the file data is read in directly using atry-except
block, which could cause troubleshooting problems down the road, as it's another area where an exception could happen. Since thejson_reader
function is already built to handle all troubleshooting related to reading in JSON data, and the file it uses is passed in as arguments, it will make the code more robust to refactor the functiongenerate_default_startup_data
to call thejson_reader
.comp_start
app, which any function that's working with this file references.