{"record":{"id":"53372da31e8d3233","repo":"apache/dolphinscheduler","slug":"the-branch-code-branchnode-is-not-in-the-dag","errorCode":null,"errorMessage":"The branch(code= ${branchNode}) is not in the dag, please check the switch task configuration","messagePattern":"The branch\\(code= (.+?)\\) is not in the dag, please check the switch task configuration","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/executor/plugin/switchtask/SwitchLogicTask.java","lineNumber":132,"sourceCode":"            }\n        }\n\n        if (nextBranch == null) {\n            log.info(\"All switch item is not satisfied\");\n            moveToDefaultBranch();\n        } else {\n            log.info(\"The condition is satisfied, move to the next branch: {}\", getTaskName(nextBranch));\n            taskParameters.setNextBranch(nextBranch);\n        }\n    }\n\n    private void checkIfBranchExist(Long branchNode) {\n        if (branchNode == null) {\n            throw new IllegalArgumentException(\"The branch is empty, please check the switch task configuration\");\n        }\n        if (workflowExecution.getWorkflowExecuteContext().getWorkflowGraph()\n                .getTaskNodeByCode(branchNode) == null) {\n            throw new IllegalArgumentException(\n                    \"The branch(code= \" + branchNode\n                            + \") is not in the dag, please check the switch task configuration\");\n        }\n    }\n\n    private String getTaskName(Long taskCode) {\n        return Optional.ofNullable(workflowExecution.getWorkflowExecuteContext())\n                .map(IWorkflowExecuteContext::getWorkflowGraph)\n                .map(iWorkflowGraph -> iWorkflowGraph.getTaskNodeByCode(taskCode))\n                .map(TaskDefinition::getName)\n                .orElse(null);\n    }\n\n    @Override\n    public void pause() {\n        log.info(\"The SwitchTask does not support pause operation\");\n    }\n","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/executor/plugin/switchtask/SwitchLogicTask.java#L114-L150","documentation":"Thrown by SwitchLogicTask.checkIfBranchExist when the chosen branch node code is non-null but does not correspond to any task node in the executing workflow graph. The master validates that the branch target exists in the DAG before following it; a dangling code means the switch task points at a task that is not part of this workflow. It aborts with IllegalArgumentException during start().","triggerScenarios":"start() on a switch task whose nextBranch code is absent from workflowExecution.getWorkflowExecuteContext().getWorkflowGraph() — typically after the branch target task was deleted or moved to another workflow while the switch task still references its old code.","commonSituations":"Deleting the downstream task that was a switch branch without rewiring the switch; copying task JSON between workflows; stale task params after workflow restructuring; import/export of workflow with mismatched task codes.","solutions":["Re-open the switch task and re-select the branch target task so the code matches a current node in the workflow.","Check that the branch task still exists in the workflow (not deleted) and is connected in the DAG.","If workflows were imported/exported, re-link the switch branches in the target workflow and re-save."],"exampleFix":"// before: branch points at deleted task code\n{\"switchResult\":{\"nextNode\":1112223330}} // task no longer in DAG\n// after: point at an existing task's code\n{\"switchResult\":{\"nextNode\":4445556660}} // code of a task present in this workflow","handlingStrategy":"validation","validationCode":"// validate branch target exists in the workflow before executing\nLong branchCode = switchResult.getNextNode();\nboolean inDag = branchCode != null &&\n    workflowExecution.getWorkflowExecuteContext().getWorkflowGraph().getTaskNodeByCode(branchCode) != null;\nif (!inDag) throw new IllegalStateException(\"Branch code \" + branchCode + \" missing from DAG\");","typeGuard":null,"tryCatchPattern":"try {\n    switchLogicTask.start();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"is not in the dag\")) {\n        // rewire the branch target in the workflow definition\n    } else throw e;\n}","preventionTips":["Never delete a task that is a switch branch without rewiring the switch task.","After importing/exporting workflows, re-verify all switch branch targets.","Avoid copying task params JSON between workflows — codes are workflow-specific."],"tags":["workflow","switch-task","dag"],"backgroundTag":"resource-not-found","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}