exception.js (1024B)
1 // YAML error class. http://stackoverflow.com/questions/8458984 2 // 3 'use strict'; 4 5 function YAMLException(reason, mark) { 6 // Super constructor 7 Error.call(this); 8 9 this.name = 'YAMLException'; 10 this.reason = reason; 11 this.mark = mark; 12 this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : ''); 13 14 // Include stack trace in error object 15 if (Error.captureStackTrace) { 16 // Chrome and NodeJS 17 Error.captureStackTrace(this, this.constructor); 18 } else { 19 // FF, IE 10+ and Safari 6+. Fallback for others 20 this.stack = (new Error()).stack || ''; 21 } 22 } 23 24 25 // Inherit from Error 26 YAMLException.prototype = Object.create(Error.prototype); 27 YAMLException.prototype.constructor = YAMLException; 28 29 30 YAMLException.prototype.toString = function toString(compact) { 31 var result = this.name + ': '; 32 33 result += this.reason || '(unknown reason)'; 34 35 if (!compact && this.mark) { 36 result += ' ' + this.mark.toString(); 37 } 38 39 return result; 40 }; 41 42 43 module.exports = YAMLException;