You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm concerned about what happens when an exception is raised inside the callback fn, but outside of the engine.render call. In my opinion, fn should be responsible for handling errors happening inside engine.render, but not for errors happening inside fn itself.
Consider an example where the code of fn contains an undefined reference. In this case an exception is raised inside the first call to fn, caught, then eventually raised again inside the second call to fn. This is not necessarily the behavior one would expect. For a concrete example, consider the following express application
varexpress=require('express');varcons=require('consolidate');varcalled=falseexpress().engine('js',cons.hogan).set('views',__dirname).get('*',function(req,res){res.render('demo.js',function(err,result){if(called)thrownewError('Already called');called=true;ress.send(result);// ress is undefined});}).listen(8080);
Here the real problem is that the variable ress is undefined, but the user receives a Error('Already called') instead. This example is inspired by a real world issue I had trying to use async.js together with consolidate.js.
I'm relatively new to express, but IMHO it would make more sense to rewrite the engine wrappers along the following lines:
Hi,
Most engines in consolidate do error handling using a code similar to this one (example taken from the Eco wrapper):
I'm concerned about what happens when an exception is raised inside the callback
fn
, but outside of theengine.render
call. In my opinion,fn
should be responsible for handling errors happening insideengine.render
, but not for errors happening insidefn
itself.Consider an example where the code of
fn
contains an undefined reference. In this case an exception is raised inside the first call tofn
, caught, then eventually raised again inside the second call tofn
. This is not necessarily the behavior one would expect. For a concrete example, consider the following express applicationHere the real problem is that the variable
ress
is undefined, but the user receives aError('Already called')
instead. This example is inspired by a real world issue I had trying to use async.js together with consolidate.js.I'm relatively new to express, but IMHO it would make more sense to rewrite the engine wrappers along the following lines:
The text was updated successfully, but these errors were encountered: