1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Improve error reporting from context plugin loading

This commit is contained in:
Nick O'Leary 2018-08-16 14:36:11 +01:00
parent dcda513901
commit 28b311b7ed
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
4 changed files with 32 additions and 13 deletions

View File

@ -162,12 +162,10 @@ function start() {
if (settings.httpStatic) { if (settings.httpStatic) {
log.info(log._("runtime.paths.httpStatic",{path:path.resolve(settings.httpStatic)})); log.info(log._("runtime.paths.httpStatic",{path:path.resolve(settings.httpStatic)}));
} }
redNodes.loadContextsPlugin().then(function () { return redNodes.loadContextsPlugin().then(function () {
redNodes.loadFlows().then(redNodes.startFlows).catch(function(err) {}); redNodes.loadFlows().then(redNodes.startFlows).catch(function(err) {});
started = true; started = true;
}); });
}).catch(function(err) {
console.log(err);
}); });
}); });
} }

View File

@ -163,7 +163,12 @@
"error-module-not-defined": "Context store '__storage__' missing 'module' option", "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": "Default context store unknown: '__storage__'", "error-invalid-default-module": "Default context store unknown: '__storage__'",
"unknown-store": "Unknown context store '__name__' specified. Using default store." "unknown-store": "Unknown context store '__name__' specified. Using default store.",
"error-loading-module": "Error loading context store: __message__",
"localfilesystem": {
"error-circular": "Context __scope__ contains a circular reference that cannot be persisted",
"error-write": "Error writing context: __message__"
}
} }
} }

View File

@ -170,6 +170,8 @@ function load() {
defaultStore = "memory"; defaultStore = "memory";
} }
return resolve(Promise.all(promises)); return resolve(Promise.all(promises));
}).catch(function(err) {
throw new Error(log._("context.error-loading-module",{message:err.toString()}));
}); });
} }

View File

@ -104,8 +104,6 @@ function loadFile(storagePath){
}else{ }else{
return Promise.resolve(undefined); return Promise.resolve(undefined);
} }
}).catch(function(err){
throw Promise.reject(err);
}); });
} }
@ -113,9 +111,21 @@ function listFiles(storagePath) {
var promises = []; var promises = [];
return fs.readdir(storagePath).then(function(files) { return fs.readdir(storagePath).then(function(files) {
files.forEach(function(file) { files.forEach(function(file) {
promises.push(fs.readdir(path.join(storagePath,file)).then(function(subdirFiles) { if (!/^\./.test(file)) {
return subdirFiles.map(subfile => path.join(file,subfile)); var fullPath = path.join(storagePath,file);
})) var stats = fs.statSync(fullPath);
if (stats.isDirectory()) {
promises.push(fs.readdir(fullPath).then(function(subdirFiles) {
var result = [];
subdirFiles.forEach(subfile => {
if (/\.json$/.test(subfile)) {
result.push(path.join(file,subfile))
}
});
return result;
}))
}
}
}); });
return Promise.all(promises); return Promise.all(promises);
}).then(dirs => dirs.reduce((acc, val) => acc.concat(val), [])); }).then(dirs => dirs.reduce((acc, val) => acc.concat(val), []));
@ -172,7 +182,7 @@ LocalFileSystem.prototype.open = function(){
if(err.code == 'ENOENT') { if(err.code == 'ENOENT') {
return fs.ensureDir(self.storageBaseDir); return fs.ensureDir(self.storageBaseDir);
}else{ }else{
return Promise.reject(err); throw err;
} }
}).then(function() { }).then(function() {
self._flushPendingWrites = function() { self._flushPendingWrites = function() {
@ -185,7 +195,7 @@ LocalFileSystem.prototype.open = function(){
var context = newContext[scope]; var context = newContext[scope];
var stringifiedContext = stringify(context); var stringifiedContext = stringify(context);
if (stringifiedContext.circular && !self.knownCircularRefs[scope]) { if (stringifiedContext.circular && !self.knownCircularRefs[scope]) {
log.warn("Context "+scope+" contains a circular reference that cannot be persisted"); log.warn(log._("error-circular",{scope:scope}));
self.knownCircularRefs[scope] = true; self.knownCircularRefs[scope] = true;
} else { } else {
delete self.knownCircularRefs[scope]; delete self.knownCircularRefs[scope];
@ -249,7 +259,11 @@ LocalFileSystem.prototype.set = function(scope, key, value, callback) {
// there's a pending write which will handle this // there's a pending write which will handle this
return; return;
} else { } else {
this._pendingWriteTimeout = setTimeout(function() { self._flushPendingWrites.call(self)}, this.flushInterval); this._pendingWriteTimeout = setTimeout(function() {
self._flushPendingWrites.call(self).catch(function(err) {
log.error(log._("context.localfilesystem.error-write",{message:err.toString()}))
});
}, this.flushInterval);
} }
} else if (callback && typeof callback !== 'function') { } else if (callback && typeof callback !== 'function') {
throw new Error("Callback must be a function"); throw new Error("Callback must be a function");
@ -272,7 +286,7 @@ LocalFileSystem.prototype.set = function(scope, key, value, callback) {
} }
var stringifiedContext = stringify(obj); var stringifiedContext = stringify(obj);
if (stringifiedContext.circular && !self.knownCircularRefs[scope]) { if (stringifiedContext.circular && !self.knownCircularRefs[scope]) {
log.warn("Context "+scope+" contains a circular reference that cannot be persisted"); log.warn(log._("error-circular",{scope:scope}));
self.knownCircularRefs[scope] = true; self.knownCircularRefs[scope] = true;
} else { } else {
delete self.knownCircularRefs[scope]; delete self.knownCircularRefs[scope];