-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Catch and ignore errors writing JSON files. #3288
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
Conversation
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 would add a statement here that the program behavior will still be correct if any given call to write_cache
is replaced with a no-op
. That makes it easier to see the logic in the other comments. Edit: by "here" I meant near the definition of write_cache
.
LGTM |
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.
Looks good to me -- I only have some suggested refactorings. Feel free to merge when you are ready.
manager.trace("Interface for {} has changed".format(id)) | ||
try: |
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.
Suggested refactoring: Move the try statement to a separate utility function to make the flow of the enclosing function easier to follow. Currently the function is too long to fit entirely on my screen, which makes code reviews harder.
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.
It's unfortunate that the error handling (including comments) is longer than the main logic of the function, but I'm hesitant about breaking it up into smaller bits. Maybe it'll fit on your screen if I move the comments elsewhere (e.g. to the function's docstring)? Anyway, we can iterate on that after the merge.
else: | ||
json.dump(meta, f) | ||
os.replace(meta_json_tmp, meta_json) | ||
try: |
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.
Like above, maybe move this to a separate function?
This is an alternative attempt at fixing issue #3215, given the
complexity of PR #3239.