Skip to content
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

Merged

Conversation

h-mayorquin
Copy link
Collaborator

Discussion from issue #910. @CodyCBakerPhD, this is what I had in mind.

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:
Copy link
Member

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

Comment on lines +244 to +246
except Exception as write_error:
nwbfile_written_succesfully = False
raise write_error
Copy link
Member

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

Copy link
Collaborator Author

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 ...

Copy link
Member

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()

@CodyCBakerPhD CodyCBakerPhD marked this pull request as ready for review June 13, 2024 18:38
@CodyCBakerPhD CodyCBakerPhD merged commit a2dadd1 into fix_overwrite_on_corrupt_file Jun 13, 2024
17 of 36 checks passed
@CodyCBakerPhD CodyCBakerPhD deleted the erase_when_failing_to_write branch June 13, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants