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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix file deletion crash if file is already gone #6677
base: main
Are you sure you want to change the base?
Fix file deletion crash if file is already gone #6677
Conversation
def try_unlink(name: str) -> None: | ||
try: | ||
os.unlink(name) | ||
except Exception: |
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.
Wondering whether this should only catch a FileNotFoundError
so as not to hide other errors. Linting requires the except not be bare at minimum so put Exception
for now
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.
FileNotFoundError makes mose sense here I think.
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.
Thanks for the PR and sorry for the slow turnaround time!
def try_unlink(name: str) -> None: | ||
try: | ||
os.unlink(name) | ||
except Exception: |
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.
FileNotFoundError makes mose sense here I think.
from mitmproxy.tools.console import master | ||
|
||
|
||
def test_try_unlink_file_not_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.
Can we use https://docs.pytest.org/en/7.1.x/how-to/tmp_path.html please? Cleaning up after mkdtemp is a bit annoying.
Description
In the event the file is no longer present, mitmproxy raises an exception in the deleting thread which is displayed in the TUI. Update to make the
os.unlink
call tolerant to file non-existence. Based on #4233Checklist