Permalink
Browse files

Prevent from crashing when failing to load module.

  • Loading branch information...
1 parent d1dfbb9 commit e17c6cb5e34866a533d0e87fe1f683d1f103d157 @guipn committed Mar 28, 2012
Showing with 26 additions and 17 deletions.
  1. +4 −5 commands.js
  2. +11 −6 dispatchers/public.js
  3. +11 −6 dispatchers/query.js
View
@@ -1,5 +1,6 @@
-var irc = require('./irc.js'),
- cmd = exports,
+var cmd = exports,
+ fs = require('fs'),
+ irc = require('./irc.js'),
authd = {}; // People authentified
cmd.prefix = /^\./;
@@ -16,12 +17,10 @@ cmd.load = function (dispatcher, context) {
var dispatcherFile = context.options.dispatcherDir +
'/' + dispatcher + '.js',
- absolutePath = require.resolve(dispatcherFile);
+ absolutePath = require.resolve(dispatcherFile);
delete require.cache[absolutePath];
-
cmd[dispatcher] = require(dispatcherFile);
-
}
View
@@ -127,12 +127,17 @@ pub.unignore.restricted = true;
pub.load = function (tokens, context) {
-
- context.cmd.load(tokens[1], context);
-
- reply(context,
- interp('Dispatcher \'{d}\' loaded.', { d: tokens[1] })
- );
+ try {
+ context.cmd.load(tokens[1], context);
+ reply(context,
+ interp('Dispatcher \'{d}\' loaded.', { d: tokens[1] })
+ );
+ }
+ catch (e) {
+ reply(context,
+ interp('Error trying to load dispatcher \'{d}\'.', { d: tokens[1] })
+ );
+ }
};
pub.load.restricted = true;
View
@@ -13,12 +13,17 @@ function reply(context, message) {
qry.load = function (tokens, context) {
-
- context.cmd.load(tokens[1], context);
-
- reply(context,
- interp('Dispatcher \'{d}\' loaded.', { d: tokens[1] })
- );
+ try {
+ context.cmd.load(tokens[1], context);
+ reply(context,
+ interp('Dispatcher \'{d}\' loaded.', { d: tokens[1] })
+ );
+ }
+ catch (e) {
+ reply(context,
+ interp('Error trying to load dispatcher \'{d}\'.', { d: tokens[1] })
+ );
+ }
};
qry.load.restricted = true;

0 comments on commit e17c6cb

Please sign in to comment.