fix error message when no filename, also try to print stack

This commit is contained in:
cloudhead 2010-06-18 19:44:48 -04:00
parent ffc7c4c094
commit 58c457f1d3
3 changed files with 14 additions and 4 deletions

View File

@ -24,6 +24,9 @@ args = args.filter(function (arg) {
case 'version':
sys.puts("lessc " + less.version.join('.') + " (LESS Compiler) [JavaScript]");
process.exit(0);
case 'verbose':
options.verbose = true;
break;
case 'h':
case 'help':
sys.puts("usage: lessc source [destination]");

View File

@ -36,11 +36,12 @@ var less = {
}
},
writeError: function (ctx) {
var message = "";
var extract = ctx.extract;
var error = [];
if (ctx.stack) {
return require('sys').error(ctx.stack);
if (!ctx.index && ctx.stack) {
return sys.error(ctx.stack);
}
if (typeof(extract[0]) === 'string') {
@ -56,8 +57,12 @@ var less = {
}
error = error.join('\n') + '\033[0m\n';
require('sys').error(stylize(ctx.message + ' of ', 'red') +
ctx.filename + ': ', error);
message += stylize(ctx.message, 'red');
ctx.filename && (message += stylize(' in ', 'red') + ctx.filename);
sys.error(message, error);
if (ctx.verbose && ctx.stack) { sys.error(stylize(ctx.stack, 'red')) }
}
};

View File

@ -238,9 +238,11 @@ less.Parser = function Parser(env) {
throw {
name: "NameError",
message: e.message,
filename: env.filename,
line: line,
stack: e.stack,
column: column,
verbose: env.verbose,
extract: [
lines[line - 2],
lines[line - 1],