Opened 10 years ago

Closed 10 years ago

#24399 closed Cleanup/optimization (fixed)

Filesystem loaders should use more specific exceptions

Reported by: Preston Timmons Owned by: nobody
Component: Template system Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The filesystem and app_directories loaders use the following pattern in load_template_source:

try:
    ...
except IOError:
    pass

If no templates can be read, TemplateDoesNotExist is raised.

This isn't optimal because an IOError can be raised for many reasons besides a file not existing, such as permission issues.

I think the file loaders should be updated to only catch the error if the errno is ENOENT.

Jinja2 does a similar check, but it includes EISDIR. Theoretically, a path could resolve to both a directory and a file. It seems like a weird use case to catch, though.

Change History (4)

comment:1 by Tim Graham, 10 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Preston Timmons, 10 years ago

Has patch: set

comment:3 by Tim Graham, 10 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Aymeric Augustin <aymeric.augustin@…>, 10 years ago

Resolution: fixed
Status: newclosed

In 70123cf084e3af7dfc61bb7bd2090ff802c3cda4:

Fixed #24399 -- Made filesystem loaders use more specific exceptions.

Note: See TracTickets for help on using tickets.
Back to Top