Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. var json = JSON.parse(result);
  2.  
  3. 1. try {
  4. 2. var json = JSON.parse(result);
  5. 3. expect(json.messages.length).to.be(1);
  6. 4. } catch(ex) {
  7. 5. throw new Error(ex.message + ". " + "JSON response: " + result);
  8. 6. }
  9.  
  10. throw new Error("JSON response: " + result, ex);
  11.  
  12. try {
  13. throw new Error('First one')
  14. } catch (error) {
  15. let e = new Error(`Rethrowing the "${error.message}" error`)
  16. e.original = error
  17. e.stack = e.stack.split('n').slice(0,2).join('n') + 'n' +
  18. error.stack
  19. throw e
  20. }
  21.  
  22. /so/42754270/test.js:9
  23. throw e
  24. ^
  25.  
  26. Error: Rethrowing the "First one" error
  27. at test (/so/42754270/test.js:5:13)
  28. Error: First one
  29. at test (/so/42754270/test.js:3:11)
  30. at Object.<anonymous> (/so/42754270/test.js:13:1)
  31. at Module._compile (module.js:570:32)
  32. at Object.Module._extensions..js (module.js:579:10)
  33. at Module.load (module.js:487:32)
  34. at tryModuleLoad (module.js:446:12)
  35. at Function.Module._load (module.js:438:3)
  36. at Module.runMain (module.js:604:10)
  37. at run (bootstrap_node.js:394:7)
  38. at startup (bootstrap_node.js:149:9)
  39.  
  40. // Standard error extender from @deployable/errors
  41.  
  42. class ExtendedError extends Error {
  43. constructor(message){
  44. super(message)
  45. this.name = this.constructor.name
  46. this.message = message
  47. if (typeof Error.captureStackTrace === 'function'){
  48. Error.captureStackTrace(this, this.constructor)
  49. } else {
  50. this.stack = (new Error(message)).stack
  51. }
  52. }
  53. }
  54.  
  55. class RethrownError extends ExtendedError {
  56. constructor(message, error){
  57. super(message)
  58. if (!error) throw new Error('RethrownError requires a message and error')
  59. this.original = error
  60. this.new_stack = this.stack
  61. let message_lines = (this.message.match(/n/g)||[]).length + 1
  62. this.stack = this.stack.split('n').slice(0, message_lines+1).join('n') + 'n' +
  63. error.stack
  64. }
  65. }
  66.  
  67. throw new RethrownError(`Oh no a "${error.message}" error`, error)
  68.  
  69. /so/42754270/test2.js:31
  70. throw new RethrownError(`Oh no a "${error.message}"" error`, error)
  71. ^
  72.  
  73. RethrownError: Oh no a "First one" error
  74. at test (/so/42754270/test2.js:31:11)
  75. Error: First one
  76. at test (/so/42754270/test2.js:29:11)
  77. at Object.<anonymous> (/so/42754270/test2.js:35:1)
  78. at Module._compile (module.js:570:32)
  79. at Object.Module._extensions..js (module.js:579:10)
  80. at Module.load (module.js:487:32)
  81. at tryModuleLoad (module.js:446:12)
  82. at Function.Module._load (module.js:438:3)
  83. at Module.runMain (module.js:604:10)
  84. at run (bootstrap_node.js:394:7)
  85. at startup (bootstrap_node.js:149:9)
  86.  
  87. file = '/home/jim/plumbers'
  88. try {
  89. JSON.parse('k')
  90. } catch (e) {
  91. let message = `JSON parse error in ${file}`
  92. let stack = new Error(message).stack
  93. e.stack = e.stack + 'nFrom previous ' + stack.split('n').slice(0,2).join('n') + 'n'
  94. throw e
  95. }
  96.  
  97. /so/42754270/throw_error_replace_stack.js:13
  98. throw e
  99. ^
  100.  
  101. SyntaxError: Unexpected token k in JSON at position 0
  102. at Object.parse (native)
  103. at Object.<anonymous> (/so/42754270/throw_error_replace_stack.js:8:13)
  104. at Module._compile (module.js:570:32)
  105. at Object.Module._extensions..js (module.js:579:10)
  106. at Module.load (module.js:487:32)
  107. at tryModuleLoad (module.js:446:12)
  108. at Function.Module._load (module.js:438:3)
  109. at Module.runMain (module.js:604:10)
  110. at run (bootstrap_node.js:394:7)
  111. at startup (bootstrap_node.js:149:9)
  112. From previous Error: JSON parse error in "/home/jim/plumbers"
  113. at Object.<anonymous> (/so/42754270/throw_error_replace_stack.js:11:20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement