gitbutlerapp/gitbutler · error
Hunk drop data must specify the source stackId and commitId
Error message
Hunk drop data must specify the source stackId and commitId
What it means
Thrown by ondropHunkData when a hunk drag-and-drop operation carries selection type 'commit' but the drop data lacks a source stackId or commitId. The handler needs both fields to locate the origin commit of the hunks being moved. This is a defensive check against malformed HunkDropDataV3 payloads constructed by the drag layer.
Solutions
- Populate stackId and commitId in the HunkDropDataV3 payload at drag start (in the code that creates the drop data for 'commit' selections).
- Check the drag source component to ensure it waits for the commit/stack to be resolved before enabling hunk dragging.
- If the source stack/commit can genuinely be unknown, use the worktree selection type instead of 'commit' or restructure HunkDropDataV3 to make the fields required.
Example fix
// before
const dropData: HunkDropDataV3 = { selectionId: { type: 'commit' }, change, hunk };
// after
const dropData: HunkDropDataV3 = { selectionId: { type: 'commit' }, stackId, commitId, change, hunk }; Defensive patterns
Strategy: validation
Validate before calling
if (data.selectionId.type === 'commit' && (!data.stackId || !data.commitId)) {
throw new Error('Drop data missing stackId/commitId');
} Type guard
function hasCommitContext(d: HunkDropDataV3): d is HunkDropDataV3 & { stackId: string; commitId: string } {
return d.selectionId.type !== 'commit' || Boolean(d.stackId && d.commitId);
} Prevention
- Make stackId/commitId required fields on the commit-variant of the drop data type so TS enforces them
- Populate the drag payload in one place at drag start
When it happens
Trigger: Calling ondropHunkData with data.selectionId.type === 'commit' while data.stackId or data.commitId is undefined/null/empty string.
Common situations: A drag payload built before stack/commit resolution completed, stale drag data referencing a deleted commit or stack, or a UI path that forgot to fill in the commit context when assembling HunkDropDataV3.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- anchor is always present in the order at this point
- Can't receive a change without it's source or commit
- Change drop data must specify the source stackId
- Change to discard at
- commits cannot be moved to the merge base
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/0df3649a5f2429be.
Report an issue: GitHub.
Appendix: source
Thrown at apps/desktop/src/lib/dragging/dropHandlers/stackDropHandler.ts:134
)
.map((h) => ({
hunkHeader: h.hunkHeader,
pathBytes: h.pathBytes,
target: this.stackTarget(stack.id),
}));
await this.diffService.assignHunk({
projectId: this.projectId,
assignments,
});
}
}
}
async ondropHunkData(data: HunkDropDataV3) {
switch (data.selectionId.type) {
case "commit": {
if (!data.stackId || !data.commitId) {
throw new Error("Hunk drop data must specify the source stackId and commitId");
}
const { stack, outcome, branchName } = await this.macros.createNewStackAndCommit();
if (!outcome.newCommit) {
throw new Error("Failed to create a new commit");
}
const previousPathBytes =
data.change.status.type === "Rename"
? data.change.status.subject.previousPathBytes
: null;
await this.macros.moveChangesToNewCommit(
stack.id,
outcome.newCommit,
data.stackId,
data.commitId,View on GitHub (pinned to 58e5313667)