Node-Red configuration
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

err.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. var test = require('tape');
  2. var ErrorWithCause = require('error-cause/Error');
  3. var inspect = require('../');
  4. test('type error', function (t) {
  5. t.plan(1);
  6. var aerr = new TypeError();
  7. aerr.foo = 555;
  8. aerr.bar = [1, 2, 3];
  9. var berr = new TypeError('tuv');
  10. berr.baz = 555;
  11. var cerr = new SyntaxError();
  12. cerr.message = 'whoa';
  13. cerr['a-b'] = 5;
  14. var withCause = new ErrorWithCause('foo', { cause: 'bar' });
  15. var withCausePlus = new ErrorWithCause('foo', { cause: 'bar' });
  16. withCausePlus.foo = 'bar';
  17. var withUndefinedCause = new ErrorWithCause('foo', { cause: undefined });
  18. var withEnumerableCause = new Error('foo');
  19. withEnumerableCause.cause = 'bar';
  20. var obj = [
  21. new TypeError(),
  22. new TypeError('xxx'),
  23. aerr,
  24. berr,
  25. cerr,
  26. withCause,
  27. withCausePlus,
  28. withUndefinedCause,
  29. withEnumerableCause
  30. ];
  31. t.equal(inspect(obj), '[ ' + [
  32. '[TypeError]',
  33. '[TypeError: xxx]',
  34. '{ [TypeError] foo: 555, bar: [ 1, 2, 3 ] }',
  35. '{ [TypeError: tuv] baz: 555 }',
  36. '{ [SyntaxError: whoa] message: \'whoa\', \'a-b\': 5 }',
  37. 'cause' in Error.prototype ? '[Error: foo]' : '{ [Error: foo] [cause]: \'bar\' }',
  38. '{ [Error: foo] ' + ('cause' in Error.prototype ? '' : '[cause]: \'bar\', ') + 'foo: \'bar\' }',
  39. 'cause' in Error.prototype ? '[Error: foo]' : '{ [Error: foo] [cause]: undefined }',
  40. '{ [Error: foo] cause: \'bar\' }'
  41. ].join(', ') + ' ]');
  42. });