Skip to content

Commit f2a0fbf

Browse files
authored
Merge pull request #237 from legraphista/fix/195
Fix: formatting in prepareStackTrace when error isn't of instance Error
2 parents 6035ef5 + 2515a8f commit f2a0fbf

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

source-map-support.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,18 @@ function wrapCallSite(frame) {
384384
}
385385

386386
// This function is part of the V8 stack trace API, for more info see:
387-
// http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
387+
// https://v8.dev/docs/stack-trace-api
388388
function prepareStackTrace(error, stack) {
389389
if (emptyCacheBetweenOperations) {
390390
fileContentsCache = {};
391391
sourceMapCache = {};
392392
}
393393

394-
return error + stack.map(function(frame) {
394+
var name = error.name || 'Error';
395+
var message = error.message || '';
396+
var errorString = name + ": " + message;
397+
398+
return errorString + stack.map(function(frame) {
395399
return '\n at ' + wrapCallSite(frame);
396400
}).join('');
397401
}

test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,3 +622,13 @@ it('handleUncaughtExceptions is true with existing listener', function(done) {
622622
done();
623623
});
624624
});
625+
626+
it('normal console.trace', function(done) {
627+
compareStdout(done, createMultiLineSourceMap(), [
628+
'require("./source-map-support").install();',
629+
'console.trace("test");'
630+
], [
631+
'Trace: test',
632+
/^ at Object\.<anonymous> \((?:.*[/\\])?line2\.js:1002:102\)$/
633+
]);
634+
});

0 commit comments

Comments
 (0)