{"record":{"id":"0df3649a5f2429be","repo":"gitbutlerapp/gitbutler","slug":"hunk-drop-data-must-specify-the-source-stackid-and-commitid","errorCode":null,"errorMessage":"Hunk drop data must specify the source stackId and commitId","messagePattern":"Hunk drop data must specify the source stackId and commitId","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/desktop/src/lib/dragging/dropHandlers/stackDropHandler.ts","lineNumber":134,"sourceCode":"\t\t\t\t\t)\n\t\t\t\t\t.map((h) => ({\n\t\t\t\t\t\thunkHeader: h.hunkHeader,\n\t\t\t\t\t\tpathBytes: h.pathBytes,\n\t\t\t\t\t\ttarget: this.stackTarget(stack.id),\n\t\t\t\t\t}));\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});\n\t\t\t}\n\t\t}\n\t}\n\n\tasync ondropHunkData(data: HunkDropDataV3) {\n\t\tswitch (data.selectionId.type) {\n\t\t\tcase \"commit\": {\n\t\t\t\tif (!data.stackId || !data.commitId) {\n\t\t\t\t\tthrow new Error(\"Hunk drop data must specify the source stackId and commitId\");\n\t\t\t\t}\n\n\t\t\t\tconst { stack, outcome, branchName } = await this.macros.createNewStackAndCommit();\n\n\t\t\t\tif (!outcome.newCommit) {\n\t\t\t\t\tthrow new Error(\"Failed to create a new commit\");\n\t\t\t\t}\n\n\t\t\t\tconst previousPathBytes =\n\t\t\t\t\tdata.change.status.type === \"Rename\"\n\t\t\t\t\t\t? data.change.status.subject.previousPathBytes\n\t\t\t\t\t\t: null;\n\n\t\t\t\tawait this.macros.moveChangesToNewCommit(\n\t\t\t\t\tstack.id,\n\t\t\t\t\toutcome.newCommit,\n\t\t\t\t\tdata.stackId,\n\t\t\t\t\tdata.commitId,","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/apps/desktop/src/lib/dragging/dropHandlers/stackDropHandler.ts#L116-L152","documentation":"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.","triggerScenarios":"Calling ondropHunkData with data.selectionId.type === 'commit' while data.stackId or data.commitId is undefined/null/empty string.","commonSituations":"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.","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."],"exampleFix":"// before\nconst dropData: HunkDropDataV3 = { selectionId: { type: 'commit' }, change, hunk };\n// after\nconst dropData: HunkDropDataV3 = { selectionId: { type: 'commit' }, stackId, commitId, change, hunk };","handlingStrategy":"validation","validationCode":"if (data.selectionId.type === 'commit' && (!data.stackId || !data.commitId)) {\n  throw new Error('Drop data missing stackId/commitId');\n}","typeGuard":"function hasCommitContext(d: HunkDropDataV3): d is HunkDropDataV3 & { stackId: string; commitId: string } {\n  return d.selectionId.type !== 'commit' || Boolean(d.stackId && d.commitId);\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["drag-and-drop","invariant","ui"],"backgroundTag":"missing-required-argument","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"}