Failed to lookup view error in pug.renderFile when using Promise.race for timeout
19.5K reputation · 20 Dec 2023, 11:04 UTC
Failed to lookup view error in pug.renderFile when applying a timeout
Goal: abort a long‑running pug.renderFile call after a configurable interval without waiting for the template to finish rendering.
Constraint: pug.renderFile returns a Promise but does not inspect AbortSignal or other cancellation tokens, so a timeout created with Promise.race only rejects the outer Promise while the internal rendering task may continue to completion, wasting CPU.
Uncertainty: whether the current approach of wrapping the Promise with a timeout is adequate, or if Pug should provide a built‑in mechanism to halt parsing early, and how to differentiate a timeout rejection from genuine errors such as “Failed to lookup view …”.
Questions: Should Pug accept an AbortSignal to cancel parsing early? Is it acceptable to rely on Promise.race for timeout handling given the possible wasted work? How can an application reliably distinguish a timeout‑induced rejection from a lookup‑failure rejection?