{"record":{"id":"38e138f667e236a2","repo":"n8n-io/n8n","slug":"nodes-from-fromjson-do-not-support-onerror","errorCode":null,"errorMessage":"Nodes from fromJSON() do not support onError()","messagePattern":"Nodes from fromJSON\\(\\) do not support onError\\(\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/workflow-sdk/src/workflow-builder/workflow-import.ts","lineNumber":103,"sourceCode":"\t\t\t\twaitBetweenTries: n8nNode.waitBetweenTries,\n\t\t\t\talwaysOutputData: n8nNode.alwaysOutputData,\n\t\t\t\tonError: n8nNode.onError,\n\t\t\t\textendsCredential: n8nNode.extendsCredential,\n\t\t\t},\n\t\t\tupdate(config) {\n\t\t\t\treturn { ...this, config: { ...this.config, ...config } };\n\t\t\t},\n\t\t\tto() {\n\t\t\t\tthrow new Error('Nodes from fromJSON() do not support to()');\n\t\t\t},\n\t\t\tinput() {\n\t\t\t\tthrow new Error('Nodes from fromJSON() do not support input()');\n\t\t\t},\n\t\t\toutput() {\n\t\t\t\tthrow new Error('Nodes from fromJSON() do not support output()');\n\t\t\t},\n\t\t\tonError() {\n\t\t\t\tthrow new Error('Nodes from fromJSON() do not support onError()');\n\t\t\t},\n\t\t\tgetConnections() {\n\t\t\t\treturn [];\n\t\t\t},\n\t\t};\n\n\t\tconst connectionsMap = new Map<string, Map<number, ConnectionTarget[]>>();\n\t\tlet mapKey = nodeName || `__unnamed_${unnamedCounter++}`;\n\n\t\t// Handle duplicate node names: generate unique key for duplicates\n\t\t// The first instance keeps the original name (connections reference it)\n\t\tif (nodes.has(mapKey)) {\n\t\t\tmapKey = generateUniqueName(nodeName, (n) => nodes.has(n));\n\t\t} else {\n\t\t\tnameToKey.set(nodeName, mapKey);\n\t\t}\n\n\t\tnodes.set(mapKey, {","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/workflow-sdk/src/workflow-builder/workflow-import.ts#L85-L121","documentation":"Imported (fromJSON) node handles do not support onError(), which on authored nodes configures per-node error behavior (e.g. routing to an error output). Imported nodes read their error settings verbatim from the JSON's onError field, so the fluent mutator is disabled. The throw prevents silently losing error-handling config that the JSON already specifies.","triggerScenarios":"Calling node.onError(...) on a handle from fromJSON() to change its error routing after import.","commonSituations":"Post-import normalization that tries to standardize error handling; helper code that sets onError uniformly on all nodes.","solutions":["Set the onError field in the source JSON before importing.","Re-author the node with the builder factory and use its .onError() API.","Use node.update({ onError: ... }) which is supported on imported handles (it returns a new config without touching connections)."],"exampleFix":"// before\nconst n = wf.getNode('X'); // imported\nn.onError(...); // throws\n\n// after (option A: edit JSON)\njson.nodes.find(x => x.name === 'X').onError = 'stopOnError';\nworkflow.fromJSON(json);\n\n// after (option B: update config)\nconst updated = n.update({ onError: 'stopOnError' });","handlingStrategy":"validation","validationCode":"function isImportedNode(n: any): boolean {\n  return n.__imported === true;\n}\nif (isImportedNode(n)) {\n  // use update() which is supported, instead of onError()\n  return n.update({ onError: 'stopOnError' });\n}","typeGuard":"function isImportedNode(n: { __imported?: boolean }): boolean {\n  return n.__imported === true;\n}","tryCatchPattern":"try {\n  n.onError('stopOnError');\n} catch (e) {\n  if (e instanceof Error && e.message.includes('fromJSON()')) {\n    return n.update({ onError: 'stopOnError' });\n  }\n  throw e;\n}","preventionTips":["Set onError in the source JSON before importing.","Use node.update({ onError }) on imported handles — it is supported.","Re-author nodes that need fluent error-handling config."],"tags":["workflow-builder","fromjson","import","error-handling"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}