emmett-framework / emmett

The web framework for inventors
BSD 3-Clause "New" or "Revised" License
1.06k stars 71 forks source link

If file not found: "During handling of the above exception, another exception occurred: ..." #146

Closed GiantCrocodile closed 8 years ago

GiantCrocodile commented 8 years ago

When I try to include a non-existing file from static directory via {{=url('static', 'img/portrait.jpg')}}

I get this exception:

> ERROR in wsgi [\weppy\wsgi.py:110]:
Application exception:
Traceback (most recent call last):
  File "\weppy\stream.py", line 50, in streamer
    stream = open(static_file, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: '\\static\\img/portrait.jpg'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "\weppy\wsgi.py", line 94, in error_handler
    return static_handler(app, environ, start_response)
  File "\weppy\wsgi.py", line 83, in static_handler
    environ, start_response, static_file, version)
  File "\weppy\stream.py", line 110, in stream_file_handler
    return streamer(environ, static_file, version, headers, block_size).to(
  File "\weppy\stream.py", line 95, in streamer
    if sys.exc_info()[1][0] in (errno.EISDIR, errno.EACCES):
TypeError: 'FileNotFoundError' object is not subscriptable
> INFO in rocket [\weppy\libs\rocket.py:1849]:
[127.0.0.1 on /static/img/portrait.jpg] dispatched in 0.011001110076904297 secon
d(s)

I think this is a bug because one exception triggers another one.

gi0baro commented 8 years ago

Yes, this probably caused by the change on standard IO exceptions since python 3.3 Will fix this asap.

GiantCrocodile commented 8 years ago

Now there is no exception thrown, if the file doesn't exist. Is this expected? I doubt it.

gi0baro commented 8 years ago

@GiantCrocodile Are you sure? You should have an empty response with status 404

GiantCrocodile commented 8 years ago

Yes, the page is loading but without the image (I only see alt-tag) and I see this in console:

[127.0.0.1 on /static/img/portrait.jpg] dispatched in 0.005000591278076172 second(s)

Edit: I see in network analyse tab of FireFox that the resource has status 404. Maybe we should print it in console too? In console it looks like it is successful dispatched which is not true.

gi0baro commented 8 years ago

@GiantCrocodile will probably enhance the response to have a body stating the error.