Alex Rivera | Logout

How can I output errors when using .less programmatically?

Asked 2011-01-25T19:53:33.110
11

I've written an ASP.NET MVC action method that receives a .less file name, processes it via Less.Parse(<filename>) and outputs the processed css file.

This works fine as long as the .less code is valid, but if there is an error, dotLess just returns an empty string. So if there is an error processing the file, my action method returns an empty css file.

How can I output an error message with a closer description of the syntax error instead?

Edit
Report

1 Answer

0

For the benefit of others, @tony722's solution works if you simply reference .less files from your pages.

But if you call Less.Parse directly, this method will write any error into Response:

var lessConfig = new DotlessConfiguration { Logger = typeof(AspResponseLogger) };
string css = Less.Parse(someInput, lessConfig);
answered 2013-04-11T02:47:19.850

Your Answer