Don't overwrite save file on failed JSON serialization, fixes file corruption problem
I created this because sometimes the saveData had something that wasn't able to be serialized and it would corrupt the save file when running json.dump(). This change creates a temp file with a datetime that is used to test whether the json serialization will succeed. This change will output a runtime error to let the user know if there is a problem and won't break the save file. On failure, the original save before the changes is maintained.
Let me know if there is anything else I can do to support this PR or if you need more info.
This is the type of error that caused me to write this code:
Traceback (most recent call last):
File "\PyFlow\App.py", line 426, in save
json.dump(saveData, tempPtr, indent=4)
File "\AppData\Local\Programs\Python\Python311\Lib\json\__init__.py", line 179, in dump
for chunk in iterable:
File "\AppData\Local\Programs\Python\Python311\Lib\json\encoder.py", line 432, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "\AppData\Local\Programs\Python\Python311\Lib\json\encoder.py", line 406, in _iterencode_dict
yield from chunks
File "\AppData\Local\Programs\Python\Python311\Lib\json\encoder.py", line 326, in _iterencode_list
yield from chunks
File "\AppData\Local\Programs\Python\Python311\Lib\json\encoder.py", line 406, in _iterencode_dict
yield from chunks
File "\AppData\Local\Programs\Python\Python311\Lib\json\encoder.py", line 406, in _iterencode_dict
yield from chunks
File "\AppData\Local\Programs\Python\Python311\Lib\json\encoder.py", line 406, in _iterencode_dict
yield from chunks
File "\AppData\Local\Programs\Python\Python311\Lib\json\encoder.py", line 439, in _iterencode
o = _default(o)
^^^^^^^^^^^
File "\AppData\Local\Programs\Python\Python311\Lib\json\encoder.py", line 180, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type getset_descriptor is not JSON serializable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "Pyflow\PyFlow\App.py", line 582, in closeEvent
if not self.save():
^^^^^^^^^^^
When this error occurs the save file will abruptly stop being written and will cut off part way through writing the json output.
This is because you are using a PIN that has serialization turned on by default.
I override this issue using a custom PIN setting it is not Storable.
self.disableOptions(PinOptions.Storable)