gitbutlerapp/gitbutler · error
No hunk assignment found for the dropped worktree hunk
Error message
No hunk assignment found for the dropped worktree hunk
What it means
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.
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.
Defensive patterns
Strategy: validation
Validate before calling
const assignment = getAssignment(data.stackId, data.change.path, data.hunk);
if (!assignment) {
toast.error('Hunk changed since drag started; try again');
return;
} Try / catch
try {
await handler.ondropHunkData(data);
} catch (e) {
if (String(e).includes('No hunk assignment')) refreshAssignments();
} Prevention
- 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
When it happens
Trigger: Calling getHunkAssignment (via assignmentReactive) with the dropped hunk's stackId, change.path and hunk, and receiving no matching assignment record.
Common situations: 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.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- Can't receive a change without it's source or commit
- Change drop data must specify the source stackId
- Failed to extract described changes from source commit
- Hunk drop data must specify the source stackId and commitId
- Selected edge endpoint wasn't found among direct neighbors
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/2953c06958dba83c.
Report an issue: GitHub.
Appendix: source
Thrown at apps/desktop/src/lib/dragging/dropHandlers/stackDropHandler.ts:184
},
],
);
break;
}
case "worktree": {
const stack = await this.stackService.newStackMutation({
projectId: this.projectId,
branch: { name: undefined },
});
const assignmentReactive = this.uncommittedService.getAssignmentByHeader(
data.stackId,
data.change.path,
data.hunk,
);
const assignment = assignmentReactive.current;
if (!assignment) {
throw new Error("No hunk assignment found for the dropped worktree hunk");
}
await this.diffService.assignHunk({
projectId: this.projectId,
assignments: [
{
hunkHeader: assignment.hunkHeader,
pathBytes: assignment.pathBytes,
target: this.stackTarget(stack.id),
},
],
});
break;
}
}
}
async ondropCommitData(data: CommitDropData): Promise<DropResult | void> {View on GitHub (pinned to 58e5313667)