Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce sync io, only ignore foreseen errors #234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions source-map-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ retrieveFileHandlers.push(function(path) {
if (xhr.readyState === 4 && xhr.status === 200) {
contents = xhr.responseText;
}
} else if (fs.existsSync(path)) {
} else {
Copy link
Author

@hulkish hulkish Jan 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both usages of fs.readFileSync are already inside a try/catch block, it's safe to just let them try the read - a missing file error (ENOENT) gets swallowed anyway

// Otherwise, use the filesystem
contents = fs.readFileSync(path, 'utf8');
}
} catch (er) {
/* ignore any errors */
} catch (err) {
if (fs && err.code !== 'ENOENT') {
throw err;
}
}

return fileContentsCache[path] = contents;
Expand Down Expand Up @@ -408,10 +410,13 @@ function getErrorSource(error) {
var contents = fileContentsCache[source];

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