I use less with node.js and I’m not so happy about it when it comes to error handling. My code looks like this:
parser.parse(data, function (err, tree) {
if(err){
console.log(err);
res.send(500);
}else{
res.header('Content-Type', 'text/css');
res.send(tree.toCSS());
}
});
My problem is that if one of my less files has a syntax error, and exception is thrown, crashing the process. Wrapping the function call in a try block doesn’t help. Is it possible to make the process fail more gracefully when there’s an error in a less file?
From what I see in the
less.jssource, theparse()function should never throw an exception because of a syntax error, but thetoCSS()function could.