diff --git a/lib/executor.js b/lib/executor.js index a4f51b9..cfbf69a 100644 --- a/lib/executor.js +++ b/lib/executor.js @@ -230,7 +230,7 @@ function runScripts(app, list, callback) { var functions = []; list.forEach(function(filepath) { debug('Requiring script %s', filepath); - var exports = tryRequire(filepath); + var exports = require(filepath); if (typeof exports === 'function') { debug('Exported function detected %s', filepath); functions.push({ @@ -257,19 +257,6 @@ function runScripts(app, list, callback) { }, callback); } -function tryRequire(modulePath) { - try { - return require.apply(this, arguments); - } catch (e) { - if (e.code === 'MODULE_NOT_FOUND') { - debug('Warning: cannot require %s - module not found.', modulePath); - return undefined; - } - console.error('failed to require "%s"', modulePath); - throw e; - } -} - function setupMiddleware(app, instructions) { if (!instructions.middleware) { // the browserified client does not support middleware diff --git a/test/executor.test.js b/test/executor.test.js index 2330266..8fd6f86 100644 --- a/test/executor.test.js +++ b/test/executor.test.js @@ -175,6 +175,17 @@ describe('executor', function() { expect(app.models.Customer._modelsWhenAttached).to.include('UniqueName'); }); + it('throws on bad require() call inside boot script', function() { + var file = appdir.writeFileSync('boot/badScript.js', + 'require("doesnt-exist"); module.exports = {};'); + + function doBoot() { + boot.execute(app, someInstructions({ files: { boot: [file] } })); + } + + expect(doBoot).to.throw(/Cannot find module \'doesnt-exist\'/); + }); + it('instantiates data sources', function() { boot.execute(app, dummyInstructions); assert(app.dataSources);