mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Handle errors when initialising library plugin
This commit is contained in:
parent
c744af161d
commit
c2347076f4
@ -15,7 +15,7 @@
|
||||
**/
|
||||
|
||||
|
||||
const {events} = require("@node-red/util")
|
||||
const {events,log} = require("@node-red/util")
|
||||
const knownTypes = {};
|
||||
const libraries = {};
|
||||
const libraryConfigs = {};
|
||||
@ -38,11 +38,19 @@ function init(runtime) {
|
||||
runtimeLibraries.forEach(library => {
|
||||
if (library.type === id) {
|
||||
library.local = false;
|
||||
libraryConfigs[library.id] = library;
|
||||
try {
|
||||
libraries[library.id] = new plugin.class(library)
|
||||
libraryConfigs[library.id] = library;
|
||||
libraryConfigs[library.id].type = id;
|
||||
if (libraries[library.id].init) {
|
||||
libraries[library.id].init();
|
||||
libraries[library.id].init().catch(err => {
|
||||
delete libraries[library.id];
|
||||
delete libraryConfigs[library.id];
|
||||
log.warn(log._("library.failedToInit",{library:library.id, error:err.toString()}));
|
||||
});
|
||||
}
|
||||
} catch(err) {
|
||||
log.warn(log._("library.failedToInit",{library:library.id, error:err.toString()}));
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -81,26 +89,26 @@ function registerType(id,type) {
|
||||
|
||||
function getEntry(library,type,path) {
|
||||
if (!knownTypes.hasOwnProperty(type)) {
|
||||
throw new Error(`Unknown library type '${type}'`);
|
||||
throw new Error(log._("library.unknownType",{type: type}))
|
||||
}
|
||||
if (libraries.hasOwnProperty(library)) {
|
||||
return libraries[library].getEntry(type,path);
|
||||
} else {
|
||||
throw new Error(`Unknown library '${library}'`);
|
||||
throw new Error(log._("library.unknownLibrary",{library: library}))
|
||||
}
|
||||
}
|
||||
function saveEntry(library,type,path,meta,body) {
|
||||
if (!knownTypes.hasOwnProperty(type)) {
|
||||
throw new Error(`Unknown library type '${type}'`);
|
||||
throw new Error(log._("library.unknownType",{type: type}))
|
||||
}
|
||||
if (libraries.hasOwnProperty(library)) {
|
||||
if (libraries[library].saveEntry) {
|
||||
return libraries[library].saveEntry(type,path,meta,body);
|
||||
} else {
|
||||
throw new Error(`Library '${library}' is read-only`);
|
||||
throw new Error(log._("library.readOnly",{library: library}))
|
||||
}
|
||||
} else {
|
||||
throw new Error(`Unknown library '${library}'`);
|
||||
throw new Error(log._("library.unknownLibrary",{library: library}))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,12 @@
|
||||
"not-available": "Settings not available",
|
||||
"property-read-only": "Property '__prop__' is read-only"
|
||||
},
|
||||
|
||||
"library": {
|
||||
"unknownLibrary": "Unknown library: __library__",
|
||||
"unknownType": "Unknown library type: __type__",
|
||||
"readOnly": "Library __library__ is read-only",
|
||||
"failedToInit": "Failed to initialise __library__: __error__"
|
||||
},
|
||||
"nodes": {
|
||||
"credentials": {
|
||||
"error":"Error loading credentials: __message__",
|
||||
|
Loading…
Reference in New Issue
Block a user