Skip to content

Commit

Permalink
handling undefined@undefined error better
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Oct 19, 2016
1 parent 1f93a07 commit 329c367
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var flatten = function(options) {
key = chalk.blue(json.name) + chalk.dim('@') + chalk.green(json.version);
}


// If we have processed this key already, just return the data object.
// This was added so that we don't recurse forever if there was a circular
// dependency in the dependency tree.
Expand Down Expand Up @@ -189,6 +190,9 @@ var flatten = function(options) {
});
});
}
if (!json.name || !json.version) {
delete data[key];
}
return data;
};

Expand Down Expand Up @@ -267,23 +271,16 @@ exports.init = function(options, callback) {
filtered = sorted;
}

if (!Object.keys(sorted).length) {
err = new Error('No packages found in this path..');
}

/*istanbul ignore next*/
if (err) {
debugError(err);
inputError = err;
}

//Initiate an error if needed (e.g. something awful happaned)
if (inputError === null && Object.keys(sorted).length === 1) {
Object.keys(sorted).forEach(function forEachCallback(item) {
var tempItem = chalk.stripColor(item);
/*istanbul ignore else*/
if (tempItem === 'undefined@undefined') {
inputError = new Error('No Npm Packages Found');
}
});
}

//Return the callback and variables nicely
callback(inputError, filtered);
});
Expand Down

0 comments on commit 329c367

Please sign in to comment.