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

Handle import errors on initial load and report to user

This commit is contained in:
Nick O'Leary 2020-11-02 21:13:52 +00:00
parent fa532da8c7
commit 2c6cda1f27
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 38 additions and 10 deletions

View File

@ -42,7 +42,8 @@
"loadNodeCatalogs": "Loading Node catalogs", "loadNodeCatalogs": "Loading Node catalogs",
"loadNodes": "Loading Nodes __count__", "loadNodes": "Loading Nodes __count__",
"loadFlows": "Loading Flows", "loadFlows": "Loading Flows",
"importFlows": "Adding Flows to workspace" "importFlows": "Adding Flows to workspace",
"importError": "<p>Error adding flows</p><p>__message__</p>"
}, },
"workspace": { "workspace": {
"defaultName": "Flow __number__", "defaultName": "Flow __number__",
@ -207,6 +208,8 @@
"download": "Download", "download": "Download",
"importUnrecognised": "Imported unrecognised type:", "importUnrecognised": "Imported unrecognised type:",
"importUnrecognised_plural": "Imported unrecognised types:", "importUnrecognised_plural": "Imported unrecognised types:",
"importDuplicate": "Imported duplicate node:",
"importDuplicate_plural": "Imported duplicate nodes:",
"nodesExported": "Nodes exported to clipboard", "nodesExported": "Nodes exported to clipboard",
"nodesImported": "Imported:", "nodesImported": "Imported:",
"nodeCopied": "__count__ node copied", "nodeCopied": "__count__ node copied",
@ -545,7 +548,7 @@
"sortRecent": "recent", "sortRecent": "recent",
"more": "+ __count__ more", "more": "+ __count__ more",
"upload": "Upload module tgz file", "upload": "Upload module tgz file",
"refresh": "Refresh module list", "refresh": "Refresh module list",
"errors": { "errors": {
"catalogLoadFailed": "<p>Failed to load node catalogue.</p><p>Check the browser console for more information</p>", "catalogLoadFailed": "<p>Failed to load node catalogue.</p><p>Check the browser console for more information</p>",
"installFailed": "<p>Failed to install: __module__</p><p>__message__</p><p>Check the log for more information</p>", "installFailed": "<p>Failed to install: __module__</p><p>__message__</p><p>Check the log for more information</p>",

View File

@ -1107,8 +1107,9 @@ RED.nodes = (function() {
if (!options.generateIds) { if (!options.generateIds) {
if (!options.importMap[id]) { if (!options.importMap[id]) {
// No conflict resolution for this node // No conflict resolution for this node
if (nodes[id] || configNodes[id] || workspaces[id] || subflows[id] || groups[id]) { var existing = nodes[id] || configNodes[id] || workspaces[id] || subflows[id] || groups[id];
existingNodes.push(id); if (existing) {
existingNodes.push({existing:existing, imported:n});
} }
} else if (options.importMap[id] === "replace") { } else if (options.importMap[id] === "replace") {
nodesToReplace.push(n); nodesToReplace.push(n);
@ -1120,7 +1121,21 @@ RED.nodes = (function() {
}) })
if (existingNodes.length > 0) { if (existingNodes.length > 0) {
var existingNodesError = new Error(); var errorMessage = RED._("clipboard.importDuplicate",{count:existingNodes.length});
var nodeList = $("<ul>");
var existingNodesCount = Math.min(5,existingNodes.length);
for (var i=0;i<existingNodesCount;i++) {
var conflict = existingNodes[i];
$("<li>").text(
conflict.existing.id+
" [ "+conflict.existing.type+ ((conflict.imported.type !== conflict.existing.type)?" | "+conflict.imported.type:"")+" ]").appendTo(nodeList)
}
if (existingNodesCount !== existingNodes.length) {
$("<li>").text(RED._("deploy.confirm.plusNMore",{count:existingNodes.length-existingNodesCount})).appendTo(nodeList)
}
var wrapper = $("<p>").append(nodeList);
var existingNodesError = new Error(errorMessage+wrapper.html());
existingNodesError.code = "import_conflict"; existingNodesError.code = "import_conflict";
existingNodesError.importConfig = identifyImportConflicts(newNodes); existingNodesError.importConfig = identifyImportConflicts(newNodes);
throw existingNodesError; throw existingNodesError;

View File

@ -178,11 +178,21 @@ var RED = (function() {
var currentHash = window.location.hash; var currentHash = window.location.hash;
RED.nodes.version(nodes.rev); RED.nodes.version(nodes.rev);
loader.reportProgress(RED._("event.importFlows"),90 ) loader.reportProgress(RED._("event.importFlows"),90 )
RED.nodes.import(nodes.flows); try {
RED.nodes.dirty(false); RED.nodes.import(nodes.flows);
RED.view.redraw(true); RED.nodes.dirty(false);
if (/^#flow\/.+$/.test(currentHash)) { RED.view.redraw(true);
RED.workspaces.show(currentHash.substring(6)); if (/^#flow\/.+$/.test(currentHash)) {
RED.workspaces.show(currentHash.substring(6));
}
} catch(err) {
RED.notify(
RED._("event.importError", {message: err.message}),
{
fixed: true,
type: 'error'
}
);
} }
} }
done(); done();