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

FileResponse is catching a FileNotFoundError to raise a RuntimeError #979

Open
bcb opened this issue Jun 20, 2020 · 3 comments
Open

FileResponse is catching a FileNotFoundError to raise a RuntimeError #979

bcb opened this issue Jun 20, 2020 · 3 comments
Labels
need confirmation This issue needs confirmation.

Comments

@bcb
Copy link

bcb commented Jun 20, 2020

Found this in FileResponse:

except FileNotFoundError:
    raise RuntimeError(f"File at path {self.path} does not exist.")

I feel this is catching one exception just to raise a less meaningful one. For my unit tests, I would prefer to expect the FileNotFoundError is raised.

@Kludex
Copy link
Member

Kludex commented Jan 30, 2022

Closing for housekeeping. I don't think a change is necessary here.

@Kludex Kludex closed this as completed Jan 30, 2022
@micky2be
Copy link

How can one catch a FileNotFoundError (404) correctly?

@toxadx
Copy link
Contributor

toxadx commented Jan 29, 2025

Raising a RuntimeError in case of a FileNotFoundError is meaningless.
FileResponse should either leave file-related exceptions as they are, allowing them to be caught by ExceptionMiddleware, or raise custom exception classes.
Please reopen the issue.

@Kludex Kludex reopened this Jan 29, 2025
@Kludex Kludex added the need confirmation This issue needs confirmation. label Jan 29, 2025
toxadx added a commit to toxadx/starlette that referenced this issue Jan 29, 2025
FileNotFoundError can be processed in exception_handlers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need confirmation This issue needs confirmation.
Projects
None yet
Development

No branches or pull requests

4 participants