robtweed/qewd

serviceModuleLoad error handling never called

killmenot opened this issue · 1 comments

Hi @robtweed

The catch block in the following example is never called because loadModule function catch issue inside and returns boolean depends on the results.

qewd/lib/appHandler.js

Lines 356 to 371 in 71a0457

try {
//this.handlers[service] = require(service).handlers;
var ok = loadModule.call(this, service, finished);
if (!ok) return;
//console.log('service module loaded for ' + service);
}
catch(err) {
error = 'Unable to load handler module: ' + service;
if (this.errorMessages && this.errorMessages[application] && this.errorMessages[application]['serviceModuleLoad']) error = this.errorMessages[application]['serviceModuleLoad'];
console.log(error + ': ' + err);
finished({
error: error,
reason: err,
service: service
});
return;

I think the correct one here is:

  1. pass information about service load to loadModule
  2. move serviceModuleLoad error handling inside loadModule function
ok = loadModule.call(this, service, finished);
if (!ok) return;

NOTE:
The code above doesn't pass information about service or application to loadModule

Please provide your thoughts...

Rob:

That try/catch is needed. If the module has bad syntax or corrupt JS in any way, then it will crash without the try/catch