Catch all errors in pluginfw/installer.js

This commit is contained in:
Marcel Klehr 2013-03-26 11:20:12 +01:00
parent e8bae61cf5
commit 9109bd206e
1 changed files with 15 additions and 12 deletions

View File

@ -6,7 +6,7 @@ var npmIsLoaded = false;
var withNpm = function (npmfn) { var withNpm = function (npmfn) {
if(npmIsLoaded) return npmfn(); if(npmIsLoaded) return npmfn();
npm.load({}, function (er) { npm.load({}, function (er) {
if (er) return cb(er); if (er) return npmfn(er);
npmIsLoaded = true; npmIsLoaded = true;
npm.on("log", function (message) { npm.on("log", function (message) {
console.log('npm: ',message) console.log('npm: ',message)
@ -16,7 +16,8 @@ var withNpm = function (npmfn) {
} }
exports.uninstall = function(plugin_name, cb) { exports.uninstall = function(plugin_name, cb) {
withNpm(function () { withNpm(function (er) {
if (er) return cb && cb(er);
npm.commands.uninstall([plugin_name], function (er) { npm.commands.uninstall([plugin_name], function (er) {
if (er) return cb && cb(er); if (er) return cb && cb(er);
hooks.aCallAll("pluginUninstall", {plugin_name: plugin_name}, function (er, data) { hooks.aCallAll("pluginUninstall", {plugin_name: plugin_name}, function (er, data) {
@ -30,7 +31,8 @@ exports.uninstall = function(plugin_name, cb) {
}; };
exports.install = function(plugin_name, cb) { exports.install = function(plugin_name, cb) {
withNpm(function () { withNpm(function (er) {
if (er) return cb && cb(er);
npm.commands.install([plugin_name], function (er) { npm.commands.install([plugin_name], function (er) {
if (er) return cb && cb(er); if (er) return cb && cb(er);
hooks.aCallAll("pluginInstall", {plugin_name: plugin_name}, function (er, data) { hooks.aCallAll("pluginInstall", {plugin_name: plugin_name}, function (er, data) {
@ -47,7 +49,8 @@ exports.availablePlugins = null;
var cacheTimestamp = 0; var cacheTimestamp = 0;
exports.getAvailablePlugins = function(maxCacheAge, cb) { exports.getAvailablePlugins = function(maxCacheAge, cb) {
withNpm(function () { withNpm(function (er) {
if (er) return cb && cb(er);
if(exports.availablePlugins && maxCacheAge && Math.round(+new Date/1000)-cacheTimestamp <= maxCacheAge) { if(exports.availablePlugins && maxCacheAge && Math.round(+new Date/1000)-cacheTimestamp <= maxCacheAge) {
return cb && cb(null, exports.availablePlugins) return cb && cb(null, exports.availablePlugins)
} }