You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
543 B

4 years ago
  1. module.exports = function createCustomError(name, message) {
  2. // use Object.create(), because some VMs prevent setting line/column otherwise
  3. // (iOS Safari 10 even throws an exception)
  4. var error = Object.create(SyntaxError.prototype);
  5. var errorStack = new Error();
  6. error.name = name;
  7. error.message = message;
  8. Object.defineProperty(error, 'stack', {
  9. get: function() {
  10. return (errorStack.stack || '').replace(/^(.+\n){1,3}/, name + ': ' + message + '\n');
  11. }
  12. });
  13. return error;
  14. };