|
|
|
|
|
'use strict'; |
|
|
|
|
|
function formatError(exception, compact) { |
|
var where = '', message = exception.reason || '(unknown reason)'; |
|
|
|
if (!exception.mark) return message; |
|
|
|
if (exception.mark.name) { |
|
where += 'in "' + exception.mark.name + '" '; |
|
} |
|
|
|
where += '(' + (exception.mark.line + 1) + ':' + (exception.mark.column + 1) + ')'; |
|
|
|
if (!compact && exception.mark.snippet) { |
|
where += '\n\n' + exception.mark.snippet; |
|
} |
|
|
|
return message + ' ' + where; |
|
} |
|
|
|
|
|
function YAMLException(reason, mark) { |
|
|
|
Error.call(this); |
|
|
|
this.name = 'YAMLException'; |
|
this.reason = reason; |
|
this.mark = mark; |
|
this.message = formatError(this, false); |
|
|
|
|
|
if (Error.captureStackTrace) { |
|
|
|
Error.captureStackTrace(this, this.constructor); |
|
} else { |
|
|
|
this.stack = (new Error()).stack || ''; |
|
} |
|
} |
|
|
|
|
|
|
|
YAMLException.prototype = Object.create(Error.prototype); |
|
YAMLException.prototype.constructor = YAMLException; |
|
|
|
|
|
YAMLException.prototype.toString = function toString(compact) { |
|
return this.name + ': ' + formatError(this, compact); |
|
}; |
|
|
|
|
|
module.exports = YAMLException; |
|
|