From 6a968d5945c048e51761aa5a9f7c0f7605a8e1dd Mon Sep 17 00:00:00 2001 From: John Maguire Date: Wed, 20 Mar 2013 19:34:43 -0400 Subject: [PATCH 1/2] add ability to unload a module whose file has been deleted --- modules/admin/commands.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/admin/commands.js b/modules/admin/commands.js index c648760..d5339d5 100644 --- a/modules/admin/commands.js +++ b/modules/admin/commands.js @@ -173,8 +173,10 @@ var commands = function(dbot) { var moduleName = event.params[1]; if(_.include(moduleNames, moduleName)) { var moduleDir = '../' + moduleName + '/'; - var cacheKey = require.resolve(moduleDir + moduleName); - delete require.cache[cacheKey]; + try { + var cacheKey = require.resolve(moduleDir + moduleName); + delete require.cache[cacheKey]; + } catch(err) { } dbot.config.moduleNames = _.without(dbot.config.moduleNames, moduleName); dbot.reloadModules(); From 3dd24e832d941aa9f7341fe1bba70c96e64e8363 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Wed, 20 Mar 2013 19:34:55 -0400 Subject: [PATCH 2/2] add check to make sure module exists before attempting to load it --- run.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/run.js b/run.js index d6237fc..69dc02b 100644 --- a/run.js +++ b/run.js @@ -155,9 +155,16 @@ DBot.prototype.reloadModules = function() { this.instance.removeListeners(); moduleNames.each(function(name) { + this.status[name] = true; + var moduleDir = './modules/' + name + '/'; - var cacheKey = require.resolve(moduleDir + name); - delete require.cache[cacheKey]; + try { + var cacheKey = require.resolve(moduleDir + name); + delete require.cache[cacheKey]; + } catch(err) { + this.status[name] = 'Error loading module: ' + err + ' ' + err.stack.split('\n')[2].trim(); + return; + } try { var webKey = require.resolve(moduleDir + 'web'); @@ -167,8 +174,6 @@ DBot.prototype.reloadModules = function() { delete require.cache[webKey]; } - this.status[name] = true; - try { // Load the module config data var config = {};