{"record":{"id":"2953c06958dba83c","repo":"gitbutlerapp/gitbutler","slug":"no-hunk-assignment-found-for-the-dropped-worktree-hunk","errorCode":null,"errorMessage":"No hunk assignment found for the dropped worktree hunk","messagePattern":"No hunk assignment found for the dropped worktree hunk","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/desktop/src/lib/dragging/dropHandlers/stackDropHandler.ts","lineNumber":184,"sourceCode":"\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"worktree\": {\n\t\t\t\tconst stack = await this.stackService.newStackMutation({\n\t\t\t\t\tprojectId: this.projectId,\n\t\t\t\t\tbranch: { name: undefined },\n\t\t\t\t});\n\n\t\t\t\tconst assignmentReactive = this.uncommittedService.getAssignmentByHeader(\n\t\t\t\t\tdata.stackId,\n\t\t\t\t\tdata.change.path,\n\t\t\t\t\tdata.hunk,\n\t\t\t\t);\n\t\t\t\tconst assignment = assignmentReactive.current;\n\t\t\t\tif (!assignment) {\n\t\t\t\t\tthrow new Error(\"No hunk assignment found for the dropped worktree hunk\");\n\t\t\t\t}\n\n\t\t\t\tawait this.diffService.assignHunk({\n\t\t\t\t\tprojectId: this.projectId,\n\t\t\t\t\tassignments: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\thunkHeader: assignment.hunkHeader,\n\t\t\t\t\t\t\tpathBytes: assignment.pathBytes,\n\t\t\t\t\t\t\ttarget: this.stackTarget(stack.id),\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tasync ondropCommitData(data: CommitDropData): Promise<DropResult | void> {","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/apps/desktop/src/lib/dragging/dropHandlers/stackDropHandler.ts#L166-L202","documentation":"Thrown when the reactive lookup for a hunk's assignment in the worktree diff returns nothing right after the drop. The code expected the dropped hunk to already exist in the assignment model so its assignee could be copied to the new commit. A missing assignment means the hunk identity (stackId, path, hunk) doesn't match any tracked assignment.","triggerScenarios":"Calling getHunkAssignment (via assignmentReactive) with the dropped hunk's stackId, change.path and hunk, and receiving no matching assignment record.","commonSituations":"The worktree changed between drag start and drop (file edited, hunks re-flowed) so the hunk no longer matches; stale or not-yet-loaded assignment data; wrong stackId passed for worktree selections.","solutions":["Confirm the stackId/path/hunk captured at drag start still match the current worktree state; recompute the hunk at drop time if the file may have changed.","Ensure the assignments store is loaded/refreshed before handling the drop (await assignment data instead of relying on possibly-stale reactive value).","If no assignment is legitimately expected (e.g. unassigned hunk), handle the undefined case gracefully instead of throwing."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const assignment = getAssignment(data.stackId, data.change.path, data.hunk);\nif (!assignment) {\n  toast.error('Hunk changed since drag started; try again');\n  return;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await handler.ondropHunkData(data);\n} catch (e) {\n  if (String(e).includes('No hunk assignment')) refreshAssignments();\n}","preventionTips":["Recompute the hunk at drop time rather than reusing drag-start coordinates","Refresh assignment data before handling drops","Disable drop targets while assignments are loading"],"tags":["hunk-assignment","drag-and-drop","stale-state"],"backgroundTag":"record-not-found","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}