starlette icon indicating copy to clipboard operation
starlette copied to clipboard

Make "Filename too long" return 404 not 500

Open Jaza opened this issue 1 year ago • 0 comments

Summary

If a static file with a really long name is requested, then it causes an OSError to be raised saying "Filename too long". This error currently gets propagated, resulting in a 500 response. In such a case, the name is too long for the underlying OS to handle, therefore a file with that name couldn't possibly exist, therefore it would be more appropriate to not propagate the error and to return a 404 response.

Checklist

  • [x] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [x] I've updated the documentation accordingly.

Note: I feel that the existing documentation is adequate, it already states:

Static files will respond with "404 Not found" or "405 Method not allowed" responses for requests which do not match.

Jaza avatar Apr 30 '24 07:04 Jaza