proper exit codes on errors, and use stderr

This commit is contained in:
cloudhead 2010-06-18 19:23:56 -04:00
parent b1dcbbd164
commit ffc7c4c094
2 changed files with 9 additions and 7 deletions

View File

@ -68,6 +68,7 @@ fs.stat(input, function (e, stats) {
}).parse(data, function (err, tree) {
if (err) {
less.writeError(err);
process.exit(1);
} else {
try {
css = tree.toCSS({ compress: options.compress });
@ -79,6 +80,7 @@ fs.stat(input, function (e, stats) {
}
} catch (e) {
less.writeError(e);
process.exit(2);
}
}
});

View File

@ -40,7 +40,7 @@ var less = {
var error = [];
if (ctx.stack) {
return require('sys').puts(ctx.stack);
return require('sys').error(ctx.stack);
}
if (typeof(extract[0]) === 'string') {
@ -56,8 +56,8 @@ var less = {
}
error = error.join('\n') + '\033[0m\n';
require('sys').puts(stylize(ctx.message + ' of ', 'red') +
ctx.filename + ': ', error);
require('sys').error(stylize(ctx.message + ' of ', 'red') +
ctx.filename + ': ', error);
}
};
@ -87,13 +87,13 @@ less.Parser.importer = function (file, paths, callback) {
if (pathname) {
fs.stat(pathname, function (e, stats) {
if (e) sys.puts(e);
if (e) sys.error(e);
fs.open(pathname, process.O_RDONLY, stats.mode, function (e, fd) {
if (e) sys.puts(e);
if (e) sys.error(e);
fs.read(fd, stats.size, 0, "utf8", function (e, data) {
if (e) sys.puts(e);
if (e) sys.error(e);
new(less.Parser)({
paths: [path.dirname(pathname)],
@ -106,7 +106,7 @@ less.Parser.importer = function (file, paths, callback) {
});
});
} else {
sys.puts("file '" + file + "' wasn't found.\n");
sys.error("file '" + file + "' wasn't found.\n");
process.exit(1);
}
}