Tidy up context store error messages

This commit is contained in:
Nick O'Leary 2018-07-23 15:20:13 +01:00
parent 9e400d9aa6
commit e9be007040
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 18 additions and 25 deletions

View File

@ -158,14 +158,12 @@
},
"context": {
"error-module-not-loaded": "'__module__' could not be loaded",
"error-loading-module": "Error loading context module '__module__': __message__ ",
"error-module-not-defined": "'module' is not defined in '__storage__' of settings.contextStorage",
"log-store-init": "Context store : '__name__' [__info__]",
"error-loading-module": "Error loading context store '__module__': __message__ ",
"error-module-not-defined": "Context store '__storage__' missing 'module' option",
"error-invalid-module-name": "Invalid context store name: '__name__'",
"error-invalid-default-module": "Invalid storage '__storage__' is specified as a default storage",
"error-use-undefined-storage": "Undefined storage '__storage__' is specified",
"unknown-store": "Unknown store '__name__' specified. Use default store instead.",
"log-store-init": "Context store : '__name__' [__info__]"
"error-invalid-default-module": "Default context store unknown: '__storage__'",
"unknown-store": "Unknown context store '__name__' specified. Using default store."
}
}

View File

@ -36,19 +36,12 @@ var unknownStores = {};
function logUnknownStore(name) {
if (name) {
var count = unknownStores[name] || 0;
if (count == 0) {
var count = unknownStores[name] || 0;
if (count == 0) {
log.warn(log._("context.unknown-store", {name: name}));
count++;
unknownStores[name] = count;
}
}
}
function logStore(name, module) {
if (name !== '_') { // ignore default store
log.info(log._("context.log-store-init",
{name:name, info:"module="+module}));
}
}
}
@ -60,6 +53,9 @@ function init(_settings) {
hasConfiguredStore = false;
var seed = settings.functionGlobalContext || {};
contexts['global'] = createContext("global",seed);
// create a default memory store - used by the unit tests that skip the full
// `load()` initialisation sequence.
// If the user has any stores configured, this will be disgarded
stores["_"] = new memory();
defaultStore = "memory";
}
@ -107,7 +103,7 @@ function load() {
try {
plugin = require("./"+plugins[pluginName].module);
} catch(err) {
return reject(new Error(log._("context.error-module-not-loaded", {module:plugins[pluginName].module})));
return reject(new Error(log._("context.error-loading-module", {module:plugins[pluginName].module,message:err.toString()})));
}
} else {
// Assume `module` is an already-required module we can use
@ -116,7 +112,7 @@ function load() {
try {
// Create a new instance of the plugin by calling its module function
stores[pluginName] = plugin(config);
logStore(pluginName, plugins[pluginName].module);
log.info(log._("context.log-store-init", {name:pluginName, info:"module="+plugins[pluginName].module}));
} catch(err) {
return reject(new Error(log._("context.error-loading-module",{module:pluginName,message:err.toString()})));
}
@ -160,6 +156,7 @@ function load() {
storeList = Object.keys(stores).filter(n=>!(defaultIsAlias && n==="default") && n!== "_");
} else {
// No configured plugins
log.info(log._("context.log-store-init", {name:"default", info:"module=memory"}));
promises.push(stores["_"].open())
storeList = ["memory"];
defaultStore = "memory";
@ -182,13 +179,11 @@ function getContextStorage(storage) {
return stores[storage];
} else if (stores.hasOwnProperty("_")) {
// Not known, but we have a default to fall back to
logUnknownStore(storage);
if (storage !== defaultStore) {
// It isn't the default store either, so log it
logUnknownStore(storage);
}
return stores["_"];
} else {
// Not known and no default configured
var contextError = new Error(log._("context.error-use-undefined-storage", {storage:storage}));
contextError.name = "ContextError";
throw contextError;
}
}