Skip to content

Commit

Permalink
fix(lib): File Transports Not Emitting Errors On ENOENT Errors
Browse files Browse the repository at this point in the history
Error handling for the `fs.stat` call in daily-rotate & file transports
was setup to only emit errors that weren't ENOENT errors. For ENOENT errors
it calls createAndFlush(0) and then does nothing to handle the error. Logic
was changed to always emit errors and call createAndFlush(0) if the error
is an ENOENT error.

fixes winstonjs#511
  • Loading branch information
Alex Bell committed Mar 16, 2015
1 parent 8ba9be0 commit 25d58af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/winston/transports/daily-rotate-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,11 @@ DailyRotateFile.prototype._createStream = function () {

fs.stat(fullname, function (err, stats) {
if (err) {
if (err.code !== 'ENOENT') {
return self.emit('error', err);
if (err.code === 'ENOENT') {
createAndFlush(0);
}

return createAndFlush(0);
return self.emit('error', err);
}

if (!stats || (self.maxsize && stats.size >= self.maxsize)) {
Expand Down
6 changes: 3 additions & 3 deletions lib/winston/transports/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,11 @@ File.prototype._createStream = function () {

fs.stat(fullname, function (err, stats) {
if (err) {
if (err.code !== 'ENOENT') {
return self.emit('error', err);
if (err.code === 'ENOENT') {
createAndFlush(0);
}

return createAndFlush(0);
return self.emit('error', err);
}

if (!stats || (self.maxsize && stats.size >= self.maxsize)) {
Expand Down

0 comments on commit 25d58af

Please sign in to comment.