gitbutlerapp/gitbutler · error · Error

No stack selected!

Error message

No stack selected!

What it means

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.

Solutions

  1. Inspect the createNewStack response — log the returned stack and verify `id` is present
  2. Fix/upgrade the stackService.create path so a created stack always carries an id
  3. Ensure the UI provides a valid stackId (select a lane/stack) before opening the commit drawer
  4. Add a retry: if the created stack has no id, re-fetch stacks for the project and resolve the id before committing

Example fix

// before
if (!finalStackId) {
  const stack = await createNewStack({ projectId, branch: { name: finalBranchName, order: 0 } });
  finalStackId = stack.id ?? undefined;
  ...
}
if (!finalStackId) {
  throw new Error("No stack selected!");
}
// after
if (!finalStackId) {
  const stack = await createNewStack({ projectId, branch: { name: finalBranchName, order: 0 } });
  finalStackId = stack.id ?? (await stackService.resolveStackId(projectId, finalBranchName));
  uiState.global.draftBranchName.set(undefined);
}
if (!finalStackId) {
  showToast({ message: "Could not resolve a stack to commit into", style: "danger" });
  return;
}
Defensive patterns

Strategy: validation

Validate before calling

const stack = stackId ? undefined : await createNewStack({ projectId, branch: { name: branchName, order: 0 } });
const finalStackId = stackId ?? stack?.id;
if (!finalStackId) {
  showToast({ message: 'Failed to resolve stack', style: 'danger' });
  return;
}

Type guard

function hasStackId(s: { id?: string | null } | undefined): s is { id: string } {
  return typeof s?.id === 'string' && s.id.length > 0;
}

Try / catch

try {
  await createCommit(message);
} catch (e) {
  if (e instanceof Error && e.message === 'No stack selected!') {
    showToast({ message: 'Could not determine the stack to commit into', style: 'danger' });
  } else { throw e; }
}

Prevention

When it happens

Trigger: 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`.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/a608dc37260928b4. Report an issue: GitHub.

Appendix: source

Thrown at apps/desktop/src/components/commit/NewCommitView.svelte:81

			// TODO: Refactor this awkward fallback somehow.
			if (!finalBranchName) {
				finalBranchName = await stackService.fetchNewBranchName(projectId);
			}
			const parentId = commitAction?.parentCommitId;
			const insertBelow = commitAction?.insertBelow;

			if (!finalStackId) {
				const stack = await createNewStack({
					projectId,
					branch: { name: finalBranchName, order: 0 },
				});
				finalStackId = stack.id ?? undefined;
				finalBranchName = stack.heads[0]?.name; // Updated to access the name property
				uiState.global.draftBranchName.set(undefined);
			}

			if (!finalStackId) {
				throw new Error("No stack selected!");
			}

			if (!finalBranchName) {
				throw new Error("No branch selected!");
			}

			// Run commit-msg hook if hooks are enabled
			let finalMessage = message;
			if ($runCommitHooks) {
				const messageHookResult = await runMessageHook({ projectId, message });
				if (messageHookResult?.status === "failure") {
					showWarning("Commit message hook failed", messageHookResult.error);
					return;
				} else if (messageHookResult?.status === "message") {
					finalMessage = messageHookResult.message;
				}
			}

View on GitHub (pinned to 58e5313667)