Skip to content

Catch and ignore errors writing JSON files.#3288

Merged
gvanrossum merged 3 commits intomasterfrom
catch-write-errors
May 2, 2017
Merged

Catch and ignore errors writing JSON files.#3288
gvanrossum merged 3 commits intomasterfrom
catch-write-errors

Conversation

@gvanrossum
Copy link
Member

This is an alternative attempt at fixing issue #3215, given the
complexity of PR #3239.

Guido van Rossum added 2 commits April 29, 2017 21:13
This is an alternative attempt at fixing issue #3215, given the
complexity of PR #3239.
Copy link
Contributor

@pkch pkch left a 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.

@pkch
Copy link
Contributor

pkch commented May 1, 2017

LGTM

Copy link
Collaborator

@JukkaL JukkaL left a 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.

data_mtime = os.path.getmtime(data_json_tmp)
os.replace(data_json_tmp, data_json)
manager.trace("Interface for {} has changed".format(id))
try:
Copy link
Collaborator

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.

Copy link
Member Author

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

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?

@gvanrossum gvanrossum merged commit ff9abd8 into master May 2, 2017
@gvanrossum gvanrossum deleted the catch-write-errors branch May 2, 2017 17:17
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.

3 participants