-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
Handle Errors Gracefully #78
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,10 +170,11 @@ function serveIndex(root, options) { | |
fstat(path, files, function (err, stats) { | ||
if (err) return next(err); | ||
|
||
// combine the stats into the file list | ||
// combine the stats into the file list, | ||
// ignoring ENOENT / null stat objects | ||
var fileList = files.map(function (file, i) { | ||
return { name: file, stat: stats[i] }; | ||
}); | ||
}).filter(function (file) { return file.stat }); | ||
|
||
// sort file list | ||
fileList.sort(fileSort); | ||
|
@@ -570,7 +571,16 @@ function fstat(dir, files, cb) { | |
files.forEach(function(file){ | ||
batch.push(function(done){ | ||
fs.stat(join(dir, file), function(err, stat){ | ||
if (err && err.code !== 'ENOENT') return done(err); | ||
// communicate errors via fake stat | ||
if (err && err.code !== 'ENOENT') { | ||
stat = { | ||
size: 0, | ||
mtime: new Date(0), | ||
error: err.toString(), | ||
code: err.code, | ||
isDirectory: function () { return false } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe your changes will expose this stat object to the users in the previous commits. I assume you made these fake values to prevent code from breaking, but it'll still break since you didn't provide all the values in a native Node.js stat object here. You'll want to make sure all the properties are covered if you're going to provide them at all, otherwise that's going to be even more confusing to the user, imo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just pushed another commit to the stat-first branch that converts to a w3 FileAPI-esque object sooner, which corrects that issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will that show up in this pr at all? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I made separate branches for each change and only based each change on the fewest number of commits needed to demonstrate the change. All of the PRs are in order. I’ll go back and add when other PR the depend on. |
||
} | ||
} | ||
|
||
// pass ENOENT as null stat, not error | ||
done(null, stat || null); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this actually be filtering anything out since the code below is providing a stat object even on error?