apache/dolphinscheduler · error · java.lang.IllegalArgumentException

The branch(code= ${branchNode}) is not in the dag, please ch

Error message

The branch(code= ${branchNode}) is not in the dag, please check the switch task configuration

What it means

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().

Source

Thrown at dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/executor/plugin/switchtask/SwitchLogicTask.java:132

            }
        }

        if (nextBranch == null) {
            log.info("All switch item is not satisfied");
            moveToDefaultBranch();
        } else {
            log.info("The condition is satisfied, move to the next branch: {}", getTaskName(nextBranch));
            taskParameters.setNextBranch(nextBranch);
        }
    }

    private void checkIfBranchExist(Long branchNode) {
        if (branchNode == null) {
            throw new IllegalArgumentException("The branch is empty, please check the switch task configuration");
        }
        if (workflowExecution.getWorkflowExecuteContext().getWorkflowGraph()
                .getTaskNodeByCode(branchNode) == null) {
            throw new IllegalArgumentException(
                    "The branch(code= " + branchNode
                            + ") is not in the dag, please check the switch task configuration");
        }
    }

    private String getTaskName(Long taskCode) {
        return Optional.ofNullable(workflowExecution.getWorkflowExecuteContext())
                .map(IWorkflowExecuteContext::getWorkflowGraph)
                .map(iWorkflowGraph -> iWorkflowGraph.getTaskNodeByCode(taskCode))
                .map(TaskDefinition::getName)
                .orElse(null);
    }

    @Override
    public void pause() {
        log.info("The SwitchTask does not support pause operation");
    }

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Re-open the switch task and re-select the branch target task so the code matches a current node in the workflow.
  2. Check that the branch task still exists in the workflow (not deleted) and is connected in the DAG.
  3. If workflows were imported/exported, re-link the switch branches in the target workflow and re-save.

Example fix

// before: branch points at deleted task code
{"switchResult":{"nextNode":1112223330}} // task no longer in DAG
// after: point at an existing task's code
{"switchResult":{"nextNode":4445556660}} // code of a task present in this workflow
Defensive patterns

Strategy: validation

Validate before calling

// validate branch target exists in the workflow before executing
Long branchCode = switchResult.getNextNode();
boolean inDag = branchCode != null &&
    workflowExecution.getWorkflowExecuteContext().getWorkflowGraph().getTaskNodeByCode(branchCode) != null;
if (!inDag) throw new IllegalStateException("Branch code " + branchCode + " missing from DAG");

Try / catch

try {
    switchLogicTask.start();
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("is not in the dag")) {
        // rewire the branch target in the workflow definition
    } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/53372da31e8d3233. Report an issue: GitHub.