css - How can I output errors when using .less programmatically? -
i've written asp.net mvc action method receives .less file name, processes via less.parse(<filename>)
, outputs processed css file.
this works fine long .less code valid, if there error, dotless returns empty string. if there error processing file, action method returns empty css file.
how can output error message closer description of syntax error instead?
the dotless parser traps exceptions , outputs them logger. snippet dotless's source performs lessengine.transformtocss
:
public string transformtocss(string source, string filename) { try { ruleset ruleset = this.parser.parse(source, filename); env env = new env(); env.compress = this.compress; env env2 = env; return ruleset.tocss(env2); } catch (parserexception exception) { this.logger.error(exception.message); } return ""; }
less.parse
has overload takes dotlessconfiguration
object, provides several properties can use:
public class dotlessconfiguration { // properties public bool cacheenabled { get; set; } public type lesssource { get; set; } public type logger { get; set; } public loglevel loglevel { get; set; } public bool minifyoutput { get; set; } public int optimization { get; set; } public bool web { get; set; } }
you notice logger
property of type type
. whatever type supply must implement dotless.core.loggers.ilogger
:
public interface ilogger { // methods void debug(string message); void error(string message); void info(string message); void log(loglevel level, string message); void warn(string message); }
as saw in first snippet, error
method on logger called when error encountered during parsing.
now, 1 sticky point of how instance of type implements ilogger
gets instantiated. internally, dotless uses ioc container baked dll. following method calls, appears call activator.createinstance
instantiate ilogger.
i hope @ least helpful.
Comments
Post a Comment