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': case 'version':
sys.puts("lessc " + less.version.join('.') + " (LESS Compiler) [JavaScript]"); sys.puts("lessc " + less.version.join('.') + " (LESS Compiler) [JavaScript]");
process.exit(0); process.exit(0);
case 'verbose':
options.verbose = true;
break;
case 'h': case 'h':
case 'help': case 'help':
sys.puts("usage: lessc source [destination]"); sys.puts("usage: lessc source [destination]");

View File

@ -36,11 +36,12 @@ var less = {
} }
}, },
writeError: function (ctx) { writeError: function (ctx) {
var message = "";
var extract = ctx.extract; var extract = ctx.extract;
var error = []; var error = [];
if (ctx.stack) { if (!ctx.index && ctx.stack) {
return require('sys').error(ctx.stack); return sys.error(ctx.stack);
} }
if (typeof(extract[0]) === 'string') { if (typeof(extract[0]) === 'string') {
@ -56,8 +57,12 @@ var less = {
} }
error = error.join('\n') + '\033[0m\n'; error = error.join('\n') + '\033[0m\n';
require('sys').error(stylize(ctx.message + ' of ', 'red') + message += stylize(ctx.message, 'red');
ctx.filename + ': ', error); 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 { throw {
name: "NameError", name: "NameError",
message: e.message, message: e.message,
filename: env.filename,
line: line, line: line,
stack: e.stack, stack: e.stack,
column: column, column: column,
verbose: env.verbose,
extract: [ extract: [
lines[line - 2], lines[line - 2],
lines[line - 1], lines[line - 1],