{"record":{"id":"a50386fccb1bce9c","repo":"n8n-io/n8n","slug":"sdk-repeated-branch-wiring","errorCode":"SDK_REPEATED_BRANCH_WIRING","errorMessage":"Repeated `.${method}()` (${info.count} times) — each call overwrites the previous target. Wire once on the workflow builder chain.","messagePattern":"Repeated `\\.(.+?)\\(\\)` \\((.+?) times\\) — each call overwrites the previous target\\. Wire once on the workflow builder chain\\.","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/@n8n/workflow-sdk/src/lint/sdk/workflow-sdk-lint.ts","lineNumber":355,"sourceCode":"\t\t\t\t\t\t\t\t\t\t...locationOf(call),\n\t\t\t\t\t\t\t\t\t\tlintTarget: 'sdk',\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{ skipChildren: isEmbeddedCodePropertyValue },\n\t);\n\n\tfor (const [key, info] of branchCounts) {\n\t\tif (info.count < 2) continue;\n\t\tconst [, method] = key.split('.');\n\t\tissues.push(\n\t\t\tlintIssue({\n\t\t\t\tcode: 'SDK_REPEATED_BRANCH_WIRING',\n\t\t\t\tmessage:\n\t\t\t\t\t`Repeated \\`.${method}()\\` (${info.count} times) — each call overwrites the previous target. ` +\n\t\t\t\t\t'Wire once on the workflow builder chain.',\n\t\t\t\tline: info.line,\n\t\t\t\tcolumn: info.column,\n\t\t\t\tlintTarget: 'sdk',\n\t\t\t}),\n\t\t);\n\t}\n\n\treturn dedupeSourceLintIssues(issues);\n}\n\n/**\n * Lint workflow SDK builder source. Skips jsCode / pythonCode property values.\n */\nexport function lintWorkflowSdkSource(source: string): SourceLintIssue[] {\n\tconst { code, asConstMatches } = prepareSourceForLint(source);","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/workflow-sdk/src/lint/sdk/workflow-sdk-lint.ts#L337-L373","documentation":"A source-lint diagnostic (code SDK_REPEATED_BRANCH_WIRING). The linter records each call to a branch method (.onTrue/.onFalse/.onCase) keyed by `${receiverName}.${method}`, then flags any key with count >= 2. In the SDK builder each such call overwrites the previous target on the same node variable instead of merging, so the earlier wiring is silently dropped.","triggerScenarios":"Calling ifNode.onTrue(a) then ifNode.onTrue(b) on the same stored node variable (b wins, a is lost). Calling switchNode.onCase(0, x) twice. The check is keyed on a direct identifier receiver, so fluent chains on workflow() are intentionally NOT flagged.","commonSituations":"Imperative style that holds a node reference and calls branch methods in sequence; refactoring that duplicates a wiring call; copy-paste of an onTrue block. The silent overwrite means the bug only shows up as a missing connection at runtime.","solutions":["Collapse the repeated calls into a single fluent chain: ifNode.onTrue(a).onFalse(b).","Use the workflow() builder chain (workflow().add(if).onTrue(a)...) which the linter treats as non-overwriting.","Delete the duplicate call so each branch method is invoked once per node variable."],"exampleFix":"// before\nconst ifNode = node('n8n-nodes-base.if', 'v1', { ... });\nifNode.onTrue(trueHandler);\nifNode.onTrue(otherHandler); // overwrites\n// after\nconst ifNode = node('n8n-nodes-base.if', 'v1', { ... });\nifNode.onTrue(trueHandler).onFalse(falseHandler);","handlingStrategy":"validation","validationCode":"import { lintWorkflowSdkSource } from '@n8n/workflow-sdk/lint';\n\nconst issues = lintWorkflowSdkSource(workflowSource);\nconst repeats = issues.filter((i) => i.code === 'SDK_REPEATED_BRANCH_WIRING');\nif (repeats.length) {\n  throw new Error(`Repeated branch wiring: ${JSON.stringify(repeats)}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer a single fluent chain (ifNode.onTrue(a).onFalse(b)) over imperative repeated calls on a stored variable.","Use the workflow() builder chain when you must call branch methods more than once — the linter exempts those.","Run lintWorkflowSdkSource before exporting to surface silent overwrites."],"tags":["lint","sdk","branching","builder","validation"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}