1
0
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:
Nick O'Leary 2014-09-20 22:25:00 +01:00
parent e2be5c6383
commit ea89aff3db

View File

@ -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]);
try {
results.push(loadNodeConfig(file,pkg.name,n)); 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,7 +445,7 @@ 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 = [];
@ -463,6 +468,14 @@ function loadNodeConfig(file,module,name) {
break; 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);
return node; return node;
} }
@ -514,7 +527,9 @@ function load(defaultNodesDir,disableNodePathScan) {
} }
var promises = []; var promises = [];
nodes.forEach(function(node) { nodes.forEach(function(node) {
if (!node.err) {
promises.push(loadNodeModule(node)); promises.push(loadNodeModule(node));
}
}); });
//resolve([]); //resolve([]);