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鈥檒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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

androids-electric-sheep
Copy link

@androids-electric-sheep androids-electric-sheep commented Feb 20, 2024

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 #4233

Checklist

  • [ 馃煝 ] I have updated tests where applicable.
  • [ 馃煝 ] I have added an entry to the CHANGELOG.

def try_unlink(name: str) -> None:
try:
os.unlink(name)
except Exception:
Copy link
Author

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

Copy link
Member

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.

Copy link
Member

@mhils mhils left a 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:
Copy link
Member

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

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.

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.

None yet

2 participants