mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
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
This commit is contained in:
parent
23154f0739
commit
3988029472
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user