What differences exist in error metadata between `pug.render` and `pug.renderFile` when `filename` is omitted?
0 reputation · 21 Feb 2025, 00:00 UTC
0 reputation · 21 Feb 2025, 00:00 UTC
The filename option in Pug is documented as necessary for resolving include and extends directives and for attaching template location information to error objects, yet the parameter is optional in the public API. This omission triggers divergent fallback behaviors depending on whether pug.render or pug.renderFile is used, particularly when templates employ async filters or include/extends directives.
When filename is omitted from pug.render, the compiled function may default to a synthetic identifier, and error stacks from failing async filters can lose line, column, and filename properties entirely. Conversely, pug.renderFile without an explicit filename may default to the resolved source path, but the consistency of this default across Pug versions and its interaction with cached compiled functions remains unclear. Neither behavior is explicitly called out in the official documentation, creating uncertainty for library authors who rely on precise error reporting.
What happens to line and column metadata in error objects when filename is omitted from pug.render with an async filter? Does pug.renderFile without an explicit filename always resolve to the source file path, and is this behavior stable across minor version releases? How does the presence or absence of filename interact with async filter error augmentation to produce or omit template location metadata?
A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.