Skip to content

Commit

Permalink
use stderr for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zaach committed May 16, 2012
1 parent 2e869ca commit ee5c2d5
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/cli.js
@@ -1,6 +1,5 @@
#!/usr/bin/env node

var util = require("util");
var fs = require("fs");
var parser = require("./jsonlint").parser;
var options = require("nomnom")
Expand Down Expand Up @@ -44,7 +43,7 @@ var options = require("nomnom")
if (options.compact) {
var fileName = options.file? options.file + ': ' : '';
parser.parseError = parser.lexer.parseError = function(str, hash) {
util.puts(fileName + 'line '+ hash.loc.first_line +', col '+ hash.loc.last_column +', found: \''+ hash.token +'\' - expected: '+ hash.expected.join(', ') +'.');
console.error(fileName + 'line '+ hash.loc.first_line +', col '+ hash.loc.last_column +', found: \''+ hash.token +'\' - expected: '+ hash.expected.join(', ') +'.');
throw new Error(str);
};
}
Expand All @@ -57,7 +56,7 @@ function parse (source) {
return JSON.stringify(parsed,null,options.indent);
} catch (e) {
if (! options.compact) {
util.puts(e);
console.log(e);
}
process.exit(1);
}
Expand All @@ -71,7 +70,7 @@ function main (args) {
if (options.inplace) {
fs.writeSync(fs.openSync(path,'w+'), source, 0, "utf8");
} else {
util.puts(source);
console.log(source);
}
} else {
var stdin = process.openStdin();
Expand All @@ -81,7 +80,7 @@ function main (args) {
source += chunk.toString('utf8');
});
stdin.on('end', function () {
util.puts(parse(source));
console.log(parse(source));
});
}
}
Expand Down

0 comments on commit ee5c2d5

Please sign in to comment.