mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Tidy up context store error messages
This commit is contained in:
parent
9e400d9aa6
commit
e9be007040
@ -158,14 +158,12 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"context": {
|
"context": {
|
||||||
"error-module-not-loaded": "'__module__' could not be loaded",
|
"log-store-init": "Context store : '__name__' [__info__]",
|
||||||
"error-loading-module": "Error loading context module '__module__': __message__ ",
|
"error-loading-module": "Error loading context store '__module__': __message__ ",
|
||||||
"error-module-not-defined": "'module' is not defined in '__storage__' of settings.contextStorage",
|
"error-module-not-defined": "Context store '__storage__' missing 'module' option",
|
||||||
"error-invalid-module-name": "Invalid context store name: '__name__'",
|
"error-invalid-module-name": "Invalid context store name: '__name__'",
|
||||||
"error-invalid-default-module": "Invalid storage '__storage__' is specified as a default storage",
|
"error-invalid-default-module": "Default context store unknown: '__storage__'",
|
||||||
"error-use-undefined-storage": "Undefined storage '__storage__' is specified",
|
"unknown-store": "Unknown context store '__name__' specified. Using default store."
|
||||||
"unknown-store": "Unknown store '__name__' specified. Use default store instead.",
|
|
||||||
"log-store-init": "Context store : '__name__' [__info__]"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -45,13 +45,6 @@ function logUnknownStore(name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function logStore(name, module) {
|
|
||||||
if (name !== '_') { // ignore default store
|
|
||||||
log.info(log._("context.log-store-init",
|
|
||||||
{name:name, info:"module="+module}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function init(_settings) {
|
function init(_settings) {
|
||||||
settings = _settings;
|
settings = _settings;
|
||||||
contexts = {};
|
contexts = {};
|
||||||
@ -60,6 +53,9 @@ function init(_settings) {
|
|||||||
hasConfiguredStore = false;
|
hasConfiguredStore = false;
|
||||||
var seed = settings.functionGlobalContext || {};
|
var seed = settings.functionGlobalContext || {};
|
||||||
contexts['global'] = createContext("global",seed);
|
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();
|
stores["_"] = new memory();
|
||||||
defaultStore = "memory";
|
defaultStore = "memory";
|
||||||
}
|
}
|
||||||
@ -107,7 +103,7 @@ function load() {
|
|||||||
try {
|
try {
|
||||||
plugin = require("./"+plugins[pluginName].module);
|
plugin = require("./"+plugins[pluginName].module);
|
||||||
} catch(err) {
|
} 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 {
|
} else {
|
||||||
// Assume `module` is an already-required module we can use
|
// Assume `module` is an already-required module we can use
|
||||||
@ -116,7 +112,7 @@ function load() {
|
|||||||
try {
|
try {
|
||||||
// Create a new instance of the plugin by calling its module function
|
// Create a new instance of the plugin by calling its module function
|
||||||
stores[pluginName] = plugin(config);
|
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) {
|
} catch(err) {
|
||||||
return reject(new Error(log._("context.error-loading-module",{module:pluginName,message:err.toString()})));
|
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!== "_");
|
storeList = Object.keys(stores).filter(n=>!(defaultIsAlias && n==="default") && n!== "_");
|
||||||
} else {
|
} else {
|
||||||
// No configured plugins
|
// No configured plugins
|
||||||
|
log.info(log._("context.log-store-init", {name:"default", info:"module=memory"}));
|
||||||
promises.push(stores["_"].open())
|
promises.push(stores["_"].open())
|
||||||
storeList = ["memory"];
|
storeList = ["memory"];
|
||||||
defaultStore = "memory";
|
defaultStore = "memory";
|
||||||
@ -182,13 +179,11 @@ function getContextStorage(storage) {
|
|||||||
return stores[storage];
|
return stores[storage];
|
||||||
} else if (stores.hasOwnProperty("_")) {
|
} else if (stores.hasOwnProperty("_")) {
|
||||||
// Not known, but we have a default to fall back to
|
// Not known, but we have a default to fall back to
|
||||||
|
if (storage !== defaultStore) {
|
||||||
|
// It isn't the default store either, so log it
|
||||||
logUnknownStore(storage);
|
logUnknownStore(storage);
|
||||||
|
}
|
||||||
return stores["_"];
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user