Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix errors mishandling that led to an exception:

ypeError: Object false has no method 'collection'
    at Array.0 (C:\anode\repo\node_modules\winston-mongodb\lib\winston-mongodb.js:74:14)
    at flushPending (C:\anode\repo\node_modules\winston-mongodb\lib\winston-mongodb.js:134:21)
    at onError (C:\anode\repo\node_modules\winston-mongodb\lib\winston-mongodb.js:144:5)
    at C:\anode\repo\node_modules\winston-mongodb\lib\winston-mongodb.js:150:14
    at C:\anode\repo\node_modules\winston-mongodb\node_modules\mongodb\lib\mongodb\db.js:170:16
    at [object Object].<anonymous> (C:\anode\repo\node_modules\winston-mongodb\node_modules\mongodb\lib\mongodb\connection\server.js:299:7)
    at [object Object].emit (events.js:67:17)
    at [object Object].<anonymous> (C:\anode\repo\node_modules\winston-mongodb\node_modules\mongodb\lib\mongodb\connection\connection_pool.js:97:15)
    at [object Object].emit (events.js:70:17)
    at Socket.<anonymous> (C:\anode\repo\node_modules\winston-mongodb\node_modules\mongodb\lib\mongodb\connection\connection.js:386:10)
  • Loading branch information...
commit cd53888ab67985cdab4cfb86e8528b1e0591af85 1 parent e595ad8
@yosefd yosefd authored
Showing with 10 additions and 8 deletions.
  1. +10 −8 lib/winston-mongodb.js
View
18 lib/winston-mongodb.js
@@ -68,12 +68,12 @@ MongoDB.prototype.log = function (level, msg, meta, callback) {
this.open(function (err) {
if (err) {
- self.emit('error', err);
+ return self.emit('error', err);
}
self._db.collection(self.collection, function (err, col) {
if (err) {
- self.emit('error', err);
+ return self.emit('error', err);
}
var entry = {
@@ -85,7 +85,7 @@ MongoDB.prototype.log = function (level, msg, meta, callback) {
col.save(entry, { safe: self.safe }, function (err, doc) {
if (err) {
- self.emit('error', err);
+ return self.emit('error', err);
}
self.emit('logged');
@@ -120,19 +120,21 @@ MongoDB.prototype.open = function (callback) {
return callback();
}
else if (this.state === 'error') {
- return callback(err);
+ return callback(self.error);
}
function flushPending (err, db) {
- self._db = db;
- self.state = 'opened';
+ if (!err) {
+ self._db = db;
+ self.state = 'opened';
+ }
//
// Iterate over all callbacks that have accumulated during
// the creation of the TCP socket.
//
for (var i = 0; i < self.pending.length; i++) {
- self.pending[i]();
+ self.pending[i](err);
}
// Quickly truncate the Array (this is more performant).
@@ -142,7 +144,7 @@ MongoDB.prototype.open = function (callback) {
function onError (err) {
self.state = 'error';
self.error = err;
- flushPending(err, false);
+ flushPending(err);
}
this.state = 'opening';
Please sign in to comment.
Something went wrong with that request. Please try again.