mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Handle node-load errors properly
Fixes #403 Certain load errors were causing start-up to fail. In particular, an npm module with a missing .js file.
This commit is contained in:
parent
e2be5c6383
commit
ea89aff3db
@ -311,6 +311,8 @@ function getNodeFiles(dir) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
valid = valid && fs.existsSync(path.join(dir,fn.replace(/\.js$/,".html")))
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
result.push(path.join(dir,fn));
|
result.push(path.join(dir,fn));
|
||||||
}
|
}
|
||||||
@ -383,7 +385,10 @@ function loadNodesFromModule(moduleDir,pkg) {
|
|||||||
for (var n in nodes) {
|
for (var n in nodes) {
|
||||||
if (nodes.hasOwnProperty(n)) {
|
if (nodes.hasOwnProperty(n)) {
|
||||||
var file = path.join(moduleDir,nodes[n]);
|
var file = path.join(moduleDir,nodes[n]);
|
||||||
results.push(loadNodeConfig(file,pkg.name,n));
|
try {
|
||||||
|
results.push(loadNodeConfig(file,pkg.name,n));
|
||||||
|
} catch(err) {
|
||||||
|
}
|
||||||
var iconDir = path.join(moduleDir,path.dirname(nodes[n]),"icons");
|
var iconDir = path.join(moduleDir,path.dirname(nodes[n]),"icons");
|
||||||
if (iconDirs.indexOf(iconDir) == -1) {
|
if (iconDirs.indexOf(iconDir) == -1) {
|
||||||
if (fs.existsSync(iconDir)) {
|
if (fs.existsSync(iconDir)) {
|
||||||
@ -440,27 +445,35 @@ function loadNodeConfig(file,module,name) {
|
|||||||
} else {
|
} else {
|
||||||
node.name = path.basename(file)
|
node.name = path.basename(file)
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
var content = fs.readFileSync(node.template,'utf8');
|
||||||
|
|
||||||
var content = fs.readFileSync(node.template,'utf8');
|
var types = [];
|
||||||
|
|
||||||
var types = [];
|
var regExp = /<script ([^>]*)data-template-name=['"]([^'"]*)['"]/gi;
|
||||||
|
var match = null;
|
||||||
|
|
||||||
var regExp = /<script ([^>]*)data-template-name=['"]([^'"]*)['"]/gi;
|
while((match = regExp.exec(content)) !== null) {
|
||||||
var match = null;
|
types.push(match[2]);
|
||||||
|
}
|
||||||
|
node.types = types;
|
||||||
|
node.config = content;
|
||||||
|
|
||||||
while((match = regExp.exec(content)) !== null) {
|
// TODO: parse out the javascript portion of the template
|
||||||
types.push(match[2]);
|
node.script = "";
|
||||||
}
|
|
||||||
node.types = types;
|
|
||||||
node.config = content;
|
|
||||||
|
|
||||||
// TODO: parse out the javascript portion of the template
|
for (var i=0;i<node.types.length;i++) {
|
||||||
node.script = "";
|
if (registry.getTypeId(node.types[i])) {
|
||||||
|
node.err = node.types[i]+" already registered";
|
||||||
for (var i=0;i<node.types.length;i++) {
|
break;
|
||||||
if (registry.getTypeId(node.types[i])) {
|
}
|
||||||
node.err = node.types[i]+" already registered";
|
}
|
||||||
break;
|
} catch(err) {
|
||||||
|
node.types = [];
|
||||||
|
if (err.code === 'ENOENT') {
|
||||||
|
node.err = "Error: "+file+" does not exist";
|
||||||
|
} else {
|
||||||
|
node.err = err.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
registry.addNodeSet(id,node);
|
registry.addNodeSet(id,node);
|
||||||
@ -514,7 +527,9 @@ function load(defaultNodesDir,disableNodePathScan) {
|
|||||||
}
|
}
|
||||||
var promises = [];
|
var promises = [];
|
||||||
nodes.forEach(function(node) {
|
nodes.forEach(function(node) {
|
||||||
promises.push(loadNodeModule(node));
|
if (!node.err) {
|
||||||
|
promises.push(loadNodeModule(node));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//resolve([]);
|
//resolve([]);
|
||||||
|
Loading…
Reference in New Issue
Block a user