Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var json = JSON.parse(result);
- 1. try {
- 2. var json = JSON.parse(result);
- 3. expect(json.messages.length).to.be(1);
- 4. } catch(ex) {
- 5. throw new Error(ex.message + ". " + "JSON response: " + result);
- 6. }
- throw new Error("JSON response: " + result, ex);
- try {
- throw new Error('First one')
- } catch (error) {
- let e = new Error(`Rethrowing the "${error.message}" error`)
- e.original = error
- e.stack = e.stack.split('n').slice(0,2).join('n') + 'n' +
- error.stack
- throw e
- }
- /so/42754270/test.js:9
- throw e
- ^
- Error: Rethrowing the "First one" error
- at test (/so/42754270/test.js:5:13)
- Error: First one
- at test (/so/42754270/test.js:3:11)
- at Object.<anonymous> (/so/42754270/test.js:13:1)
- at Module._compile (module.js:570:32)
- at Object.Module._extensions..js (module.js:579:10)
- at Module.load (module.js:487:32)
- at tryModuleLoad (module.js:446:12)
- at Function.Module._load (module.js:438:3)
- at Module.runMain (module.js:604:10)
- at run (bootstrap_node.js:394:7)
- at startup (bootstrap_node.js:149:9)
- // Standard error extender from @deployable/errors
- class ExtendedError extends Error {
- constructor(message){
- super(message)
- this.name = this.constructor.name
- this.message = message
- if (typeof Error.captureStackTrace === 'function'){
- Error.captureStackTrace(this, this.constructor)
- } else {
- this.stack = (new Error(message)).stack
- }
- }
- }
- class RethrownError extends ExtendedError {
- constructor(message, error){
- super(message)
- if (!error) throw new Error('RethrownError requires a message and error')
- this.original = error
- this.new_stack = this.stack
- let message_lines = (this.message.match(/n/g)||[]).length + 1
- this.stack = this.stack.split('n').slice(0, message_lines+1).join('n') + 'n' +
- error.stack
- }
- }
- throw new RethrownError(`Oh no a "${error.message}" error`, error)
- /so/42754270/test2.js:31
- throw new RethrownError(`Oh no a "${error.message}"" error`, error)
- ^
- RethrownError: Oh no a "First one" error
- at test (/so/42754270/test2.js:31:11)
- Error: First one
- at test (/so/42754270/test2.js:29:11)
- at Object.<anonymous> (/so/42754270/test2.js:35:1)
- at Module._compile (module.js:570:32)
- at Object.Module._extensions..js (module.js:579:10)
- at Module.load (module.js:487:32)
- at tryModuleLoad (module.js:446:12)
- at Function.Module._load (module.js:438:3)
- at Module.runMain (module.js:604:10)
- at run (bootstrap_node.js:394:7)
- at startup (bootstrap_node.js:149:9)
- file = '/home/jim/plumbers'
- try {
- JSON.parse('k')
- } catch (e) {
- let message = `JSON parse error in ${file}`
- let stack = new Error(message).stack
- e.stack = e.stack + 'nFrom previous ' + stack.split('n').slice(0,2).join('n') + 'n'
- throw e
- }
- /so/42754270/throw_error_replace_stack.js:13
- throw e
- ^
- SyntaxError: Unexpected token k in JSON at position 0
- at Object.parse (native)
- at Object.<anonymous> (/so/42754270/throw_error_replace_stack.js:8:13)
- at Module._compile (module.js:570:32)
- at Object.Module._extensions..js (module.js:579:10)
- at Module.load (module.js:487:32)
- at tryModuleLoad (module.js:446:12)
- at Function.Module._load (module.js:438:3)
- at Module.runMain (module.js:604:10)
- at run (bootstrap_node.js:394:7)
- at startup (bootstrap_node.js:149:9)
- From previous Error: JSON parse error in "/home/jim/plumbers"
- at Object.<anonymous> (/so/42754270/throw_error_replace_stack.js:11:20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement