-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add logic to erase file if writing fails #912
add logic to erase file if writing fails #912
Conversation
if not nwbfile_loaded_succesfully and not file_initially_exists: # Not sure we need this | ||
nwbfile_path_in.unlink() | ||
|
||
if not nwbfile_written_succesfully and not file_initially_exists: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from better variable naming, the key difference in this PR is this line by limiting the global notion of 'success' to just 'success during write process' and if file didn't initially exist but write started and failed, try to clean it up
Emphasis on 'try' since not guaranteed to succeed without error
except Exception as write_error: | ||
nwbfile_written_succesfully = False | ||
raise write_error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, you also added a capture block here to further scope the success of the operation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I think this is the core. Separating errors from loading or creating from errors of writing.
But as you were mentioning maybe us handling unlinking is not a good idea ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case we're attempting to leave the system as we left it, which is fine
The case I am against is what you don't have here
if any_error_condition and file_initially_exists:
nwbfile_path_in.unlink()
a2dadd1
into
fix_overwrite_on_corrupt_file
Discussion from issue #910. @CodyCBakerPhD, this is what I had in mind.