mirror of
https://github.com/circlecell/jsonlint-mod.git
synced 2026-01-21 05:07:49 +08:00
Report dougJSONParse errors in same format as other parse errors
This commit is contained in:
@@ -67,7 +67,12 @@ var options = require("./nomnom")
|
||||
if (options.compact) {
|
||||
var fileName = options.file? options.file + ': ' : '';
|
||||
parser.parseError = parser.lexer.parseError = function(str, hash) {
|
||||
console.error(fileName + 'line '+ hash.loc.first_line +', col '+ hash.loc.last_column +', found: \''+ hash.token +'\' - expected: '+ hash.expected.join(', ') +'.');
|
||||
// error from dougJSONParse
|
||||
if (hash.message) {
|
||||
console.error(fileName + 'line '+ hash.line +', col '+ hash.col +',', hash.message + '.');
|
||||
} else {
|
||||
console.error(fileName + 'line '+ hash.loc.first_line +', col '+ hash.loc.last_column +', found: \''+ hash.token +'\' - expected: '+ hash.expected.join(', ') +'.');
|
||||
}
|
||||
throw new Error(str);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -422,8 +422,12 @@ jsonlint.parse = function(input) {
|
||||
dougJSONParse(input);
|
||||
} catch(e) {
|
||||
if(/Duplicate key|Bad string|Unexpected/.test(e.message)) {
|
||||
var lineNumber = input.substring(0, e.at).split('\n').length;
|
||||
throw SyntaxError(e.message + ' on line ' + lineNumber);
|
||||
var linesUntilError = input.substring(0, e.at).split('\n');
|
||||
var line = linesUntilError.length;
|
||||
var col = linesUntilError[line - 1].length - 1;
|
||||
|
||||
this.parseError(e.message, {line: line, col: col, message: e.message.replace(/./, function(l) { return l.toLowerCase(); })});
|
||||
throw SyntaxError(e.message + ' on line ' + line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user