exception.js 1.0 KB

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