{"record":{"id":"cf34a7a9b535e964","repo":"n8n-io/n8n","slug":"oncase-is-only-available-on-switch-nodes-nod","errorCode":null,"errorMessage":".onCase() is only available on Switch nodes (${NODE_TYPES.SWITCH})","messagePattern":"\\.onCase\\(\\) is only available on Switch nodes \\((.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/workflow-sdk/src/workflow-builder/node-builders/node-builder.ts","lineNumber":349,"sourceCode":"\t\tif (!isIfNodeType(this.type)) {\n\t\t\tthrow new Error(`.onFalse() is only available on IF nodes (${NODE_TYPES.IF})`);\n\t\t}\n\t\tconst builder = new IfElseBuilderImpl<TOutput>(\n\t\t\tthis as unknown as NodeInstance<'n8n-nodes-base.if', string, TOutput>,\n\t\t);\n\t\treturn builder.onFalse(target);\n\t}\n\n\t/**\n\t * Start building a Switch case with a case target.\n\t * Only available on Switch nodes (n8n-nodes-base.switch).\n\t *\n\t * @example\n\t * switchNode.onCase(0, caseA).onCase(1, caseB)\n\t */\n\tonCase(index: number, target: SwitchCaseTarget): SwitchCaseBuilder<TOutput> {\n\t\tif (!isSwitchNodeType(this.type)) {\n\t\t\tthrow new Error(`.onCase() is only available on Switch nodes (${NODE_TYPES.SWITCH})`);\n\t\t}\n\t\tconst builder = new SwitchCaseBuilderImpl<TOutput>(\n\t\t\tthis as unknown as NodeInstance<'n8n-nodes-base.switch', string, TOutput>,\n\t\t);\n\t\treturn builder.onCase(index, target);\n\t}\n\n\tonError<T extends NodeInstance<string, string, unknown>>(handler: T | InputTarget): this {\n\t\t// Declaring an error route implies the error output port exists.\n\t\tthis.config.onError ??= 'continueErrorOutput';\n\t\tif (isInputTarget(handler)) {\n\t\t\tthis._connections.push({\n\t\t\t\ttarget: handler.node,\n\t\t\t\toutputIndex: 0,\n\t\t\t\ttargetInputIndex: handler.inputIndex,\n\t\t\t\tconnectionType: 'error',\n\t\t\t});\n\t\t} else {","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/workflow-sdk/src/workflow-builder/node-builders/node-builder.ts#L331-L367","documentation":"Thrown by NodeInstanceImpl.onCase() when isSwitchNodeType(this.type) returns false. The .onCase(index, target) branch builder targets a specific case output index that only exists on n8n-nodes-base.switch nodes; calling it on any other node type is rejected.","triggerScenarios":"Calling someNode.onCase(0, target) where someNode is an IF, Code, HTTP, or any non-Switch node; using an IF node's output indexing to drive case wiring.","commonSituations":"Wrong node type selected (IF used where Switch was meant); copy-paste from a Switch example; dynamic node construction with the wrong type string.","solutions":["Create the node with type 'n8n-nodes-base.switch' before calling .onCase().","For IF nodes use .onTrue()/.onFalse(); for plain fan-out use .to().","Narrow with isSwitchNodeType before calling .onCase()."],"exampleFix":"// before\nconst n = node('n8n-nodes-base.if', 'v1', { ... });\nn.onCase(0, handler); // throws\n// after\nconst sw = node('n8n-nodes-base.switch', 'v1', { ... });\nsw.onCase(0, caseA).onCase(1, caseB);","handlingStrategy":"type-guard","validationCode":"function assertSwitchNode(node: NodeInstance): asserts node is NodeInstance<'n8n-nodes-base.switch', string, unknown> {\n  if (node.type !== 'n8n-nodes-base.switch') {\n    throw new Error(`.onCase() requires a Switch node, got ${node.type}`);\n  }\n}\n\nassertSwitchNode(myNode);\nmyNode.onCase(0, handler);","typeGuard":"import { isSwitchNodeType } from '@n8n/workflow-sdk';\n\nfunction isSwitchNode(node: NodeInstance): node is NodeInstance<'n8n-nodes-base.switch', string, unknown> {\n  return isSwitchNodeType(node.type);\n}","tryCatchPattern":null,"preventionTips":["Create Switch nodes explicitly with node('n8n-nodes-base.switch', ...).","Narrow with isSwitchNodeType before calling .onCase().","Reserve .onCase() for Switch nodes; use .onTrue()/.onFalse() for IF and .to() for plain fan-out."],"tags":["runtime","builder","switch-node","branching"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}