Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions source-map-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ retrieveFileHandlers.push(function(path) {
}
} else if (fs.existsSync(path)) {
// Otherwise, use the filesystem
contents = fs.readFileSync(path, 'utf8');
try {
contents = fs.readFileSync(path, 'utf8');
} catch (er) {
contents = '';
}
}

return fileContentsCache[path] = contents;
Expand Down Expand Up @@ -388,7 +392,11 @@ function getErrorSource(error) {

// Support files on disk
if (!contents && fs && fs.existsSync(source)) {
contents = fs.readFileSync(source, 'utf8');
try {
contents = fs.readFileSync(source, 'utf8');
} catch (er) {
contents = '';
}
}

// Format the line from the original source code like node does
Expand Down
22 changes: 22 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,28 @@ it('normal throw', function() {
]);
});

/* The following test duplicates some of the code in
* `normal throw` but triggers file read failure.
*/
it('fs.readFileSync failure', function() {
compareStackTrace(createMultiLineSourceMap(), [
'var fs = require("fs");',
'var rfs = fs.readFileSync;',
'fs.readFileSync = function() {',
' throw new Error("no rfs for you");',
'};',
'try {',
' throw new Error("test");',
'} finally {',
' fs.readFileSync = rfs;',
'}'
], [
'Error: test',
/^ at Object\.exports\.test \((?:.*[/\\])?line7\.js:1007:107\)$/
]);
});


it('throw inside function', function() {
compareStackTrace(createMultiLineSourceMap(), [
'function foo() {',
Expand Down