Skip to content

Commit

Permalink
Ensure source snippets also output URLs/paths in the correct format, …
Browse files Browse the repository at this point in the history
…matching stack frame
  • Loading branch information
cspotcode committed Apr 29, 2022
1 parent 2b315b8 commit 69012b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions source-map-support.js
Expand Up @@ -617,12 +617,12 @@ function getErrorSource(error) {
// Support the inline sourceContents inside the source map
var contents = getFileContentsCache(source);

source = tryFileURLToPath(source);
const sourceAsPath = tryFileURLToPath(source);

// Support files on disk
if (!contents && fs && fs.existsSync(source)) {
if (!contents && fs && fs.existsSync(sourceAsPath)) {
try {
contents = fs.readFileSync(source, 'utf8');
contents = fs.readFileSync(sourceAsPath, 'utf8');
} catch (er) {
contents = '';
}
Expand Down
18 changes: 9 additions & 9 deletions test.js
Expand Up @@ -446,7 +446,7 @@ it('native function', async function() {
'[1].map(function(x) { throw new Error(x); });'
], [
'Error: 1',
re`[/\\].original-${id}.js`,
re`${stackFramePathStartsWith()}(?:.*[/\\])?.original-${id}.js`,
/at Array\.map \((native|<anonymous>)\)/
]);
});
Expand Down Expand Up @@ -475,7 +475,7 @@ it('throw in Timeout with empty source map', function(done) {
' throw new Error("this is the error")',
'})'
], [
re`[/\\].generated-${id}.${extension}:3$`,
re`${stackFramePathStartsWith()}(?:.*[/\\])?.generated-${id}.${extension}:3$`,
' throw new Error("this is the error")',
/^ \^$/,
'Error: this is the error',
Expand Down Expand Up @@ -544,7 +544,7 @@ it('default options', function(done) {
'process.nextTick(foo);',
'process.nextTick(function() { process.exit(1); });'
], [
re`[/\\].original-${id}\.js:1$`,
re`${stackFramePathStartsWith()}(?:.*[/\\])?.original-${id}\.js:1$`,
'this is the original code',
'^',
'Error: this is the error',
Expand All @@ -559,7 +559,7 @@ it('handleUncaughtExceptions is true', function(done) {
'require("./source-map-support").install({ handleUncaughtExceptions: true });',
'process.nextTick(foo);'
], [
re`[/\\].original-${id}\.js:1$`,
re`${stackFramePathStartsWith()}(?:.*[/\\])?.original-${id}\.js:1$`,
'this is the original code',
'^',
'Error: this is the error',
Expand All @@ -574,7 +574,7 @@ it('handleUncaughtExceptions is false', function(done) {
'require("./source-map-support").install({ handleUncaughtExceptions: false });',
'process.nextTick(foo);'
], [
re`[/\\].generated-${id}.${extension}:2$`,
re`${stackFramePathStartsWith()}(?:.*[/\\])?.generated-${id}.${extension}:2$`,
'function foo() { throw new Error("this is the error"); }',

' ^',
Expand All @@ -591,7 +591,7 @@ it('default options with empty source map', function(done) {
'require("./source-map-support").install();',
'process.nextTick(foo);'
], [
re`[/\\].generated-${id}.${extension}:2$`,
re`${stackFramePathStartsWith()}(?:.*[/\\])?.generated-${id}.${extension}:2$`,
'function foo() { throw new Error("this is the error"); }',
' ^',
'Error: this is the error',
Expand All @@ -606,7 +606,7 @@ it('default options with source map with gap', function(done) {
'require("./source-map-support").install();',
'process.nextTick(foo);'
], [
re`[/\\].generated-${id}.${extension}:2$`,
re`${stackFramePathStartsWith()}(?:.*[/\\])?.generated-${id}.${extension}:2$`,
'function foo() { throw new Error("this is the error"); }',
' ^',
'Error: this is the error',
Expand Down Expand Up @@ -637,7 +637,7 @@ it('sourcesContent', function(done) {
'process.nextTick(foo);',
'process.nextTick(function() { process.exit(1); });'
], [
re`[/\\]original-${id}\.js:1002$`,
re`${stackFramePathStartsWith()}(?:.*[/\\])?original-${id}\.js:1002$`,
' line 2',
' ^',
'Error: this is the error',
Expand Down Expand Up @@ -851,7 +851,7 @@ it('supports multiple instances', function(done) {
' process.nextTick(function() { process.exit(1); });',
'})();'
], [
re`[/\\].original2-${id}\.js:1$`,
re`${stackFramePathStartsWith()}(?:.*[/\\])?.original2-${id}\.js:1$`,
'this is some other original code',
'^',
'Error: this is the error',
Expand Down

0 comments on commit 69012b9

Please sign in to comment.