Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

AbstractClass.findOne should return null for not found #128

Closed
pyramation opened this Issue · 1 comment

2 participants

@pyramation

If you use libraries that do any asynchronous flow control, the findOne method can cause some hard-to-find bugs in your code, because no value is passed into the callback for objects not found.

I suggest that null is passed when objects aren't found, so that there is at least a null object returned.

https://github.com/1602/jugglingdb/blob/master/lib/abstract-class.js#L390

uses:

this.all(params, function (err, collection) {
    if (err || !collection || !collection.length > 0) return cb(err);
    cb(err, collection[0]);
});

but should do:

this.all(params, function (err, collection) {
    if (err) return cb(err);
    if (!collection || !collection.length > 0) return cb(null, null);
    cb(err, collection[0]);
});

If you are interested, my use-case was the async.waterfall using async.js, and calling Model.findOne(ops, callback) as one function in the array of callbacks

@1602
Owner
@1602 1602 closed this in cefd79d
@anatoliychakkaev anatoliychakkaev referenced this issue from a commit in anatoliychakkaev/jugglingdb
@1602 Update test for #128 c6d7360
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.