From 3988029472161b5275d565b402d971a8d81ae4ef Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 2 Apr 2020 19:18:06 +0100 Subject: [PATCH] Refactored scheduling adapter loader to better display errors no issue - missing modules required by an adapter weren't flagged up as missing, but that the entire adapter was missing - therefore, it was difficult to see what you were missing - this commit handles the case where a module is missing, and displays an error --- core/server/adapters/scheduling/utils.js | 26 +++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/core/server/adapters/scheduling/utils.js b/core/server/adapters/scheduling/utils.js index 39c3078fb2..a2051a46b1 100644 --- a/core/server/adapters/scheduling/utils.js +++ b/core/server/adapters/scheduling/utils.js @@ -55,11 +55,13 @@ exports.createAdapter = function (options) { // CASE: only throw error if module does exist if (err.code !== 'MODULE_NOT_FOUND') { return Promise.reject(new common.errors.IncorrectUsageError({err})); - // CASE: if module not found it can be an error within the adapter (cannot find bluebird for example) - } else if (err.code === 'MODULE_NOT_FOUND' && err.message.indexOf(contentPath + activeAdapter) === -1) { + } + + // CASE: if module not found it can be an error within the adapter (cannot find bluebird for example) + if (err.code === 'MODULE_NOT_FOUND' && err.message.indexOf(contentPath + activeAdapter) === -1) { return Promise.reject(new common.errors.IncorrectUsageError({ - err, - help: `Please check the imports are valid in ${contentPath}${activeAdapter}` + message: `You are missing dependencies required in your adapter ${contentPath}${activeAdapter}`, + err })); } } @@ -71,13 +73,23 @@ exports.createAdapter = function (options) { adapter = adapter || new (require(internalPath + activeAdapter))(options); } catch (err) { // CASE: only throw error if module does exist - if (err.code === 'MODULE_NOT_FOUND') { + if (err.code !== 'MODULE_NOT_FOUND') { + return Promise.reject(new common.errors.IncorrectUsageError({err})); + } + + // CASE: if module not found it can be an error within the adapter (cannot find bluebird for example) + if (err.code === 'MODULE_NOT_FOUND' && err.message.indexOf(internalPath + activeAdapter) === -1) { return Promise.reject(new common.errors.IncorrectUsageError({ - message: `We cannot find your adapter in: ${contentPath} or: ${internalPath}` + message: `You are missing dependencies required in your adapter ${internalPath}${activeAdapter}`, + err })); } - return Promise.reject(new common.errors.IncorrectUsageError({err})); + // Finally, the adapter cannot be found + return Promise.reject(new common.errors.IncorrectUsageError({ + message: `We cannot find your adapter '${activeAdapter}' in ${contentPath} or ${internalPath}`, + err + })); } if (!(adapter instanceof SchedulingBase)) {