hkoba / yatt_lite

YATT::Lite - Template with "use strict"
Other
5 stars 0 forks source link

Module loading errors during template renderings result in incomplete contents (with status 500) #209

Closed hkoba closed 2 years ago

hkoba commented 2 years ago

SiteApp::call doesn't handle $con->prop->{is_error} case correctly. It can result in incomplete content when module loading error occurs during template rendering.

Background

YATT::Lite sets $SIG{__DIE__} handler to capture as many errors as possible during its template rendering. Unfortunately, this does not work well with eval { require MaybeMissingModule } idioms that try to load specified modules. To solve this problem partially, permissive_require() was introduced in #200. But if you forget it and use plain require() instead, the problem harms you. So, this problem should be solved on another level.

The following codes illustrate the above situation. If you use &yatt:backend(); in templates, a module loading error occurs, and you get incomplete content.

# app.psgi
Entity backend => sub {
  require SomeModule; # instead of YATT::Lite::Util::permissive_require('SomeModule'), which is recommended.
  SomeModule->do_something();
};

# SomeModule.pm
package AnotherModule;

if (eval {require MaybeMissingModule}) {
  MaybeMissingModule->xxx
} else {
  # do fallback
}