node-triton#94 Protect against cache lookup returning null

If the cache file does not exist _cacheGetJson will not pass any value to the callback.

In the getImage function the callback passed to _cacheGetJson assumes if there was no error value then the second argument must be an array.

Add some logic to guard against null values before iterating over the array.
This commit is contained in:
Kris Shannon 2016-02-15 03:58:29 +11:00 committed by Trent Mick
parent 314a05b082
commit bcf55f0a63
1 changed files with 6 additions and 4 deletions

View File

@ -354,10 +354,12 @@ TritonApi.prototype.getImage = function getImage(opts, cb) {
next(err);
return;
}
for (var i = 0; i < images.length; i++) {
if (images[i].id === opts.name) {
img = images[i];
break;
if (images) {
for (var i = 0; i < images.length; i++) {
if (images[i].id === opts.name) {
img = images[i];
break;
}
}
}
next();