apache/dolphinscheduler · error · IllegalArgumentException
"Cannot find task: " + taskName
Error message
"Cannot find task: " + taskName
What it means
getTaskNodeByName looks up a TaskDefinition by its name in the workflow graph's name-indexed map. If no task with that name exists in the graph, it throws this IllegalArgumentException. The graph only contains tasks that were part of the workflow definition it was built from.
Source
Thrown at dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/graph/WorkflowGraph.java:90
.map(Map.Entry::getKey)
.collect(Collectors.toList());
}
@Override
public Set<String> getPredecessors(String taskName) {
return new HashSet<>(predecessors.get(taskName));
}
@Override
public Set<String> getSuccessors(String taskName) {
return new HashSet<>(successors.get(taskName));
}
@Override
public TaskDefinition getTaskNodeByName(String taskName) {
TaskDefinition taskDefinition = taskDefinitionMap.get(taskName);
if (taskDefinition == null) {
throw new IllegalArgumentException("Cannot find task: " + taskName);
}
return taskDefinition;
}
@Override
public TaskDefinition getTaskNodeByCode(Long taskCode) {
TaskDefinition taskDefinition = taskDefinitionCodeMap.get(taskCode);
if (taskDefinition == null) {
throw new IllegalArgumentException("Cannot find task: " + taskCode);
}
return taskDefinition;
}
@Override
public List<TaskDefinition> getAllTaskNodes() {
return new ArrayList<>(taskDefinitionMap.values());
}
View on GitHub (pinned to 02eac45a1b)
Solutions
- Verify the exact task name exists in the workflow definition (getAllTaskNodes()) before calling getTaskNodeByName
- Use getTaskNodeByCode(Long) with the stable task code instead of the mutable name
- If the task was renamed, update the caller's configuration/code with the new name
- Catch IllegalArgumentException and handle the missing-task case explicitly where absence is expected
Example fix
// before
TaskDefinition td = workflowGraph.getTaskNodeByName("PRCESS_DATA"); // typo
// after
String name = "PROCESS_DATA";
boolean exists = workflowGraph.getAllTaskNodes().stream().anyMatch(t -> t.getName().equals(name));
if (!exists) throw new IllegalStateException("Workflow has no task named " + name);
TaskDefinition td = workflowGraph.getTaskNodeByName(name); Defensive patterns
Strategy: validation
Validate before calling
boolean exists = workflowGraph.getAllTaskNodes().stream()
.anyMatch(t -> t.getName().equals(taskName));
if (!exists) throw new IllegalStateException("No task named " + taskName + " in this workflow"); Type guard
Optional<TaskDefinition> findByName(WorkflowGraph g, String name) {
return g.getAllTaskNodes().stream().filter(t -> t.getName().equals(name)).findFirst();
} Try / catch
try {
TaskDefinition td = workflowGraph.getTaskNodeByName(taskName);
} catch (IllegalArgumentException e) {
log.warn("Task {} not found in workflow graph", taskName, e);
return null; // or skip this dependent
} Prevention
- Reference tasks by code (stable) rather than name (mutable)
- Check the workflow definition after renames/deletions and update all referencing logic
- Match names exactly — no case-insensitive or trimmed assumptions
- Validate task names in workflow JSON/DAG editors before saving
When it happens
Trigger: Calling workflowGraph.getTaskNodeByName(name) with a task name that is not among the workflow's task definitions — e.g. a name typed incorrectly, a task removed from the workflow, or a name belonging to another workflow.
Common situations: Logic/workflow code referencing a task that was renamed or deleted; case-mismatched task names; querying a partially-started workflow where only some tasks were added to the graph; stale failover/recovery logic referencing old task names.
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
- "Cannot find task: " + taskCode
- Can not find any datasource by name %s
- Can not find valid workflow by name %s
- Can not find valid project by name %s
- Can not find valid resource by name %s
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/9e59920813597f32.
Report an issue: GitHub.