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

Enabling and disabling non-existent nodes throws an error

This commit is contained in:
Anna Thomas 2014-11-27 16:42:45 +00:00
parent ec43fc4fe2
commit 57bc83b2a7
2 changed files with 11 additions and 9 deletions

View File

@ -319,13 +319,15 @@ var registry = (function() {
if (!settings.available()) {
throw new Error("Settings unavailable");
}
var id = typeOrId;
if (nodeTypeToId[typeOrId]) {
id = nodeTypeToId[typeOrId];
}
var config = moduleConfigs[getModule(id)].nodes[getNode(id)];
if (config) {
var config;
try {
config = moduleConfigs[getModule(id)].nodes[getNode(id)];
delete config.err;
config.enabled = true;
if (!config.loaded) {
@ -334,7 +336,7 @@ var registry = (function() {
}
nodeConfigCache = null;
saveNodeList();
} else {
} catch (err) {
throw new Error("Unrecognised id: "+typeOrId);
}
return filterNodeInfo(config);
@ -348,14 +350,14 @@ var registry = (function() {
if (nodeTypeToId[typeOrId]) {
id = nodeTypeToId[typeOrId];
}
var config = moduleConfigs[getModule(id)].nodes[getNode(id)];
if (config) {
var config;
try {
config = moduleConfigs[getModule(id)].nodes[getNode(id)];
// TODO: persist setting
config.enabled = false;
nodeConfigCache = null;
saveNodeList();
} else {
} catch (err) {
throw new Error("Unrecognised id: "+id);
}
return filterNodeInfo(config);

View File

@ -991,14 +991,14 @@ describe('NodeRegistry', function() {
});
it('fails to enable/disable non-existent nodes', function(done) {
typeRegistry.init(settings);
typeRegistry.init(settingsWithStorage);
typeRegistry.load("wontexist",true).then(function() {
var list = typeRegistry.getNodeList();
list.should.be.an.Array.and.be.empty;
/*jshint immed: false */
(function() {
typeRegistry.disableNode("123");
typeRegistry.disableNode("123");
}).should.throw();
/*jshint immed: false */