From fb4a4817ef1dbac915a2e1391bd60520ec7aa539 Mon Sep 17 00:00:00 2001 From: Katharina Irrgang Date: Wed, 24 Aug 2016 14:32:29 +0200 Subject: [PATCH] improvement: storage error handling (#7257) no issue - while testing different situations for custom storage adapters after switching from 0.9 to 0.10, it turned out the error output was not optimal - this PR improves that --- core/server/storage/index.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/core/server/storage/index.js b/core/server/storage/index.js index cebdf65004..86f3a36cae 100644 --- a/core/server/storage/index.js +++ b/core/server/storage/index.js @@ -24,14 +24,27 @@ function getStorage(type) { } // CASE: load adapter from custom path (.../content/storage) - // CASE: load adapter from default path (.../server/storage) try { storage[storageChoice] = require(config.paths.storagePath.custom + storageChoice); - } catch (err1) { - try { - storage[storageChoice] = require(config.paths.storagePath.default + storageChoice); - } catch (err2) { - throw err2; + } catch (err) { + // CASE: only throw error if module does exist + if (err.code !== 'MODULE_NOT_FOUND') { + throw new errors.IncorrectUsage(err.message); + } + // 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(config.paths.storagePath.custom + storageChoice) === -1) { + throw new errors.IncorrectUsage(err.message); + } + } + + // CASE: either storage[storageChoice] is already set or why check for in the default storage path + try { + storage[storageChoice] = storage[storageChoice] || require(config.paths.storagePath.default + storageChoice); + } catch (err) { + if (err.code === 'MODULE_NOT_FOUND') { + throw new errors.IncorrectUsage('We cannot find your adpter in: ' + config.paths.storagePath.custom + ' or: ' + config.paths.storagePath.default); + } else { + throw new errors.IncorrectUsage(err.message); } }