{"record":{"id":"a608dc37260928b4","repo":"gitbutlerapp/gitbutler","slug":"no-stack-selected","errorCode":null,"errorMessage":"No stack selected!","messagePattern":"No stack selected!","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/desktop/src/components/commit/NewCommitView.svelte","lineNumber":81,"sourceCode":"\t\t\t// TODO: Refactor this awkward fallback somehow.\n\t\t\tif (!finalBranchName) {\n\t\t\t\tfinalBranchName = await stackService.fetchNewBranchName(projectId);\n\t\t\t}\n\t\t\tconst parentId = commitAction?.parentCommitId;\n\t\t\tconst insertBelow = commitAction?.insertBelow;\n\n\t\t\tif (!finalStackId) {\n\t\t\t\tconst stack = await createNewStack({\n\t\t\t\t\tprojectId,\n\t\t\t\t\tbranch: { name: finalBranchName, order: 0 },\n\t\t\t\t});\n\t\t\t\tfinalStackId = stack.id ?? undefined;\n\t\t\t\tfinalBranchName = stack.heads[0]?.name; // Updated to access the name property\n\t\t\t\tuiState.global.draftBranchName.set(undefined);\n\t\t\t}\n\n\t\t\tif (!finalStackId) {\n\t\t\t\tthrow new Error(\"No stack selected!\");\n\t\t\t}\n\n\t\t\tif (!finalBranchName) {\n\t\t\t\tthrow new Error(\"No branch selected!\");\n\t\t\t}\n\n\t\t\t// Run commit-msg hook if hooks are enabled\n\t\t\tlet finalMessage = message;\n\t\t\tif ($runCommitHooks) {\n\t\t\t\tconst messageHookResult = await runMessageHook({ projectId, message });\n\t\t\t\tif (messageHookResult?.status === \"failure\") {\n\t\t\t\t\tshowWarning(\"Commit message hook failed\", messageHookResult.error);\n\t\t\t\t\treturn;\n\t\t\t\t} else if (messageHookResult?.status === \"message\") {\n\t\t\t\t\tfinalMessage = messageHookResult.message;\n\t\t\t\t}\n\t\t\t}\n","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/apps/desktop/src/components/commit/NewCommitView.svelte#L63-L99","documentation":"In NewCommitView.svelte, createCommit throws Error(\"No stack selected!\") when `finalStackId` remains falsy after the create-new-stack fallback path. This happens when a new stack is created but stack.id is undefined, so there is no stack to commit into — an invariant violation before proceeding with the commit.","triggerScenarios":"Calling createCommit (via handleCommitCreation) with no stackId in context, then createNewStack returns a stack whose `id` is null/undefined, leaving finalStackId undefined after `stack.id ?? undefined`.","commonSituations":"Backend fails to assign an id to a newly created stack; the createNewStack response shape changed; racing state where the stack was created concurrently and the response omits id; mocked service returning partial stack objects in tests.","solutions":["Inspect the createNewStack response — log the returned stack and verify `id` is present","Fix/upgrade the stackService.create path so a created stack always carries an id","Ensure the UI provides a valid stackId (select a lane/stack) before opening the commit drawer","Add a retry: if the created stack has no id, re-fetch stacks for the project and resolve the id before committing"],"exampleFix":"// before\nif (!finalStackId) {\n  const stack = await createNewStack({ projectId, branch: { name: finalBranchName, order: 0 } });\n  finalStackId = stack.id ?? undefined;\n  ...\n}\nif (!finalStackId) {\n  throw new Error(\"No stack selected!\");\n}\n// after\nif (!finalStackId) {\n  const stack = await createNewStack({ projectId, branch: { name: finalBranchName, order: 0 } });\n  finalStackId = stack.id ?? (await stackService.resolveStackId(projectId, finalBranchName));\n  uiState.global.draftBranchName.set(undefined);\n}\nif (!finalStackId) {\n  showToast({ message: \"Could not resolve a stack to commit into\", style: \"danger\" });\n  return;\n}","handlingStrategy":"validation","validationCode":"const stack = stackId ? undefined : await createNewStack({ projectId, branch: { name: branchName, order: 0 } });\nconst finalStackId = stackId ?? stack?.id;\nif (!finalStackId) {\n  showToast({ message: 'Failed to resolve stack', style: 'danger' });\n  return;\n}","typeGuard":"function hasStackId(s: { id?: string | null } | undefined): s is { id: string } {\n  return typeof s?.id === 'string' && s.id.length > 0;\n}","tryCatchPattern":"try {\n  await createCommit(message);\n} catch (e) {\n  if (e instanceof Error && e.message === 'No stack selected!') {\n    showToast({ message: 'Could not determine the stack to commit into', style: 'danger' });\n  } else { throw e; }\n}","preventionTips":["Assert createNewStack always returns a stack with an id (contract test)","Verify backend responses for stack creation include ids","Select a stack/lane before opening the commit drawer when possible","Refresh stack state after concurrent operations to avoid stale/missing ids"],"tags":["svelte","ui-state","guard"],"backgroundTag":"internal-invariant-violation","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"}