@@ -410,29 +410,50 @@ function REPLServer(prompt, |
410 | 410 |
|
411 | 411 | self._domain.on('error', function debugDomainError(e) { |
412 | 412 | debug('domain error'); |
413 | | - const top = replMap.get(self); |
414 | | - const pstrace = Error.prepareStackTrace; |
415 | | - Error.prepareStackTrace = prepareStackTrace(pstrace); |
416 | | - if (typeof e === 'object') |
| 413 | + let errStack = ''; |
| 414 | + |
| 415 | + if (typeof e === 'object' && e !== null) { |
| 416 | + const pstrace = Error.prepareStackTrace; |
| 417 | + Error.prepareStackTrace = prepareStackTrace(pstrace); |
417 | 418 | internalUtil.decorateErrorStack(e); |
418 | | - Error.prepareStackTrace = pstrace; |
419 | | - const isError = internalUtil.isError(e); |
420 | | - if (!self.underscoreErrAssigned) |
421 | | - self.lastError = e; |
422 | | - if (e instanceof SyntaxError && e.stack) { |
423 | | - // remove repl:line-number and stack trace |
424 | | - e.stack = e.stack |
425 | | - .replace(/^repl:\d+\r?\n/, '') |
426 | | - .replace(/^\s+at\s.*\n?/gm, ''); |
427 | | - } else if (isError && self.replMode === exports.REPL_MODE_STRICT) { |
428 | | - e.stack = e.stack.replace(/(\s+at\s+repl:)(\d+)/, |
429 | | - (_, pre, line) => pre + (line - 1)); |
| 419 | + Error.prepareStackTrace = pstrace; |
| 420 | + |
| 421 | + if (e.domainThrown) { |
| 422 | + delete e.domain; |
| 423 | + delete e.domainThrown; |
| 424 | + } |
| 425 | + |
| 426 | + if (internalUtil.isError(e)) { |
| 427 | + if (e.stack) { |
| 428 | + if (e.name === 'SyntaxError') { |
| 429 | + // Remove stack trace. |
| 430 | + e.stack = e.stack |
| 431 | + .replace(/^repl:\d+\r?\n/, '') |
| 432 | + .replace(/^\s+at\s.*\n?/gm, ''); |
| 433 | + } else if (self.replMode === exports.REPL_MODE_STRICT) { |
| 434 | + e.stack = e.stack.replace(/(\s+at\s+repl:)(\d+)/, |
| 435 | + (_, pre, line) => pre + (line - 1)); |
| 436 | + } |
| 437 | + } |
| 438 | + errStack = util.inspect(e); |
| 439 | + |
| 440 | + // Remove one line error braces to keep the old style in place. |
| 441 | + if (errStack[errStack.length - 1] === ']') { |
| 442 | + errStack = errStack.slice(1, -1); |
| 443 | + } |
| 444 | + } |
430 | 445 | } |
431 | | - if (isError && e.stack) { |
432 | | - top.outputStream.write(`${e.stack}\n`); |
433 | | - } else { |
434 | | - top.outputStream.write(`Thrown: ${String(e)}\n`); |
| 446 | + |
| 447 | + if (errStack === '') { |
| 448 | + errStack = `Thrown: ${util.inspect(e)}`; |
435 | 449 | } |
| 450 | + |
| 451 | + if (!self.underscoreErrAssigned) { |
| 452 | + self.lastError = e; |
| 453 | + } |
| 454 | + |
| 455 | + const top = replMap.get(self); |
| 456 | + top.outputStream.write(`${errStack}\n`); |
436 | 457 | top.clearBufferedCommand(); |
437 | 458 | top.lines.level = []; |
438 | 459 | top.displayPrompt(); |
|