1
0
mirror of synced 2025-12-19 05:14:08 +08:00

use stderr for errors

This commit is contained in:
Zachary Carter
2012-05-15 19:53:35 -07:00
parent 2e869ca7ec
commit ee5c2d557c

View File

@@ -1,6 +1,5 @@
#!/usr/bin/env node #!/usr/bin/env node
var util = require("util");
var fs = require("fs"); var fs = require("fs");
var parser = require("./jsonlint").parser; var parser = require("./jsonlint").parser;
var options = require("nomnom") var options = require("nomnom")
@@ -44,7 +43,7 @@ var options = require("nomnom")
if (options.compact) { if (options.compact) {
var fileName = options.file? options.file + ': ' : ''; var fileName = options.file? options.file + ': ' : '';
parser.parseError = parser.lexer.parseError = function(str, hash) { 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); throw new Error(str);
}; };
} }
@@ -57,7 +56,7 @@ function parse (source) {
return JSON.stringify(parsed,null,options.indent); return JSON.stringify(parsed,null,options.indent);
} catch (e) { } catch (e) {
if (! options.compact) { if (! options.compact) {
util.puts(e); console.log(e);
} }
process.exit(1); process.exit(1);
} }
@@ -71,7 +70,7 @@ function main (args) {
if (options.inplace) { if (options.inplace) {
fs.writeSync(fs.openSync(path,'w+'), source, 0, "utf8"); fs.writeSync(fs.openSync(path,'w+'), source, 0, "utf8");
} else { } else {
util.puts(source); console.log(source);
} }
} else { } else {
var stdin = process.openStdin(); var stdin = process.openStdin();
@@ -81,7 +80,7 @@ function main (args) {
source += chunk.toString('utf8'); source += chunk.toString('utf8');
}); });
stdin.on('end', function () { stdin.on('end', function () {
util.puts(parse(source)); console.log(parse(source));
}); });
} }
} }