{"record":{"id":"82c5af6498ef9403","repo":"apache/dolphinscheduler","slug":"cannot-find-task-taskcode","errorCode":null,"errorMessage":"\"Cannot find task: \" + taskCode","messagePattern":"\"Cannot find task: \" \\+ taskCode","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/graph/WorkflowGraph.java","lineNumber":99,"sourceCode":"    @Override\n    public Set<String> getSuccessors(String taskName) {\n        return new HashSet<>(successors.get(taskName));\n    }\n\n    @Override\n    public TaskDefinition getTaskNodeByName(String taskName) {\n        TaskDefinition taskDefinition = taskDefinitionMap.get(taskName);\n        if (taskDefinition == null) {\n            throw new IllegalArgumentException(\"Cannot find task: \" + taskName);\n        }\n        return taskDefinition;\n    }\n\n    @Override\n    public TaskDefinition getTaskNodeByCode(Long taskCode) {\n        TaskDefinition taskDefinition = taskDefinitionCodeMap.get(taskCode);\n        if (taskDefinition == null) {\n            throw new IllegalArgumentException(\"Cannot find task: \" + taskCode);\n        }\n        return taskDefinition;\n    }\n\n    @Override\n    public List<TaskDefinition> getAllTaskNodes() {\n        return new ArrayList<>(taskDefinitionMap.values());\n    }\n\n    private void addTaskNodes(List<TaskDefinition> taskDefinitions) {\n        taskDefinitions\n                .stream()\n                .map(TaskDefinition::getName)\n                .forEach(taskDefinition -> {\n                    if (predecessors.containsKey(taskDefinition) || successors.containsKey(taskDefinition)) {\n                        throw new IllegalArgumentException(\"The task \" + taskDefinition + \" is already exists\");\n                    }\n                    predecessors.put(taskDefinition, new ArrayList<>());","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/graph/WorkflowGraph.java#L81-L117","documentation":"getTaskNodeByCode looks up a TaskDefinition by its numeric code in the graph's code-indexed map. If no task with that code exists in this workflow's graph, it throws this IllegalArgumentException. Task codes are workflow-scoped here, so a code from another workflow will not resolve.","triggerScenarios":"Calling workflowGraph.getTaskNodeByCode(code) with a code not present in the workflow — e.g. a relation or dispatch record referencing a task that was deleted, or a code copied from a different workflow.","commonSituations":"Task deleted from the workflow but still referenced by old task instances, dependents, or recovery/failover records; DB migration issues mixing codes across workflows; hard-coded codes in scripts after re-importing a workflow (re-import regenerates codes).","solutions":["Confirm the task code exists in the workflow definition (taskDefinitionCodeMap is populated from the workflow's tasks) before lookup","Use getTaskNodeByName if only the name is reliably known","Re-derive codes from the current workflow definition instead of persisting/storing old codes across re-imports","Catch IllegalArgumentException when scanning historical data that may reference removed tasks"],"exampleFix":"// before\nlong code = 1234567890L; // from an old export\nTaskDefinition td = workflowGraph.getTaskNodeByCode(code);\n// after\nTaskDefinition td = workflowGraph.getAllTaskNodes().stream()\n        .filter(t -> t.getCode() == code).findFirst()\n        .orElseThrow(() -> new IllegalStateException(\"Task code \" + code + \" is not part of this workflow\"));","handlingStrategy":"validation","validationCode":"boolean exists = workflowGraph.getAllTaskNodes().stream()\n        .anyMatch(t -> t.getCode() == taskCode);\nif (!exists) throw new IllegalStateException(\"Task code \" + taskCode + \" not in this workflow\");","typeGuard":null,"tryCatchPattern":"try {\n    TaskDefinition td = workflowGraph.getTaskNodeByCode(taskCode);\n} catch (IllegalArgumentException e) {\n    log.warn(\"Skipping historical reference to missing task code {}\", taskCode);\n    return null;\n}","preventionTips":["Do not persist task codes across workflow re-imports (codes are regenerated)","When deleting a task, clean up all relations and references to its code","Scope code lookups to the correct workflow version/snapshot","Filter historical/recovery data to codes present in the current definition"],"tags":["workflow-graph","task-lookup","not-found"],"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-14T00:17:10.932Z"}