better error handling

This commit is contained in:
cloudhead 2010-06-11 21:46:24 -04:00
parent c63ade697a
commit 0477f14dde
3 changed files with 15 additions and 6 deletions

View File

@ -69,12 +69,16 @@ fs.stat(input, function (e, stats) {
if (err) {
less.writeError(err);
} else {
css = tree.toCSS({ compress: options.compress });
if (output) {
fd = fs.openSync(output, "w");
fs.writeSync(fd, css, 0, "utf8");
} else {
sys.print(css);
try {
css = tree.toCSS({ compress: options.compress });
if (output) {
fd = fs.openSync(output, "w");
fs.writeSync(fd, css, 0, "utf8");
} else {
sys.print(css);
}
} catch (e) {
less.writeError(e);
}
}
});

View File

@ -39,6 +39,10 @@ var less = {
var extract = ctx.extract;
var error = [];
if (ctx.stack) {
return require('sys').puts(ctx.stack);
}
if (typeof(extract[0]) === 'string') {
error.push(stylize((ctx.line - 1) + ' ' + extract[0], 'grey'));
}

View File

@ -236,6 +236,7 @@ less.Parser = function Parser(env) {
name: "NameError",
message: e.message,
line: line,
stack: e.stack,
column: column,
extract: [
lines[line - 2],