Skip to content

Commit 665351f

Browse files
only21milcodexclaude
authored
fix(web): show readable errors when a stack action fails (#24118)
Co-authored-by: GPT-6.1 Sol <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent c2dc2ea commit 665351f

2 files changed

Lines changed: 82 additions & 1 deletion

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
2+
import { EnvironmentId, ProjectId } from "@t3tools/contracts";
3+
import { expect, it, vi } from "vite-plus/test";
4+
import { page } from "vite-plus/test/browser";
5+
6+
const state = vi.hoisted(() => ({ detail: "" }));
7+
8+
vi.mock(import("~/state/use-atom-command"), async () => {
9+
const { PullRequestOperationError } = await import("@t3tools/contracts");
10+
const { Cause } = await import("effect");
11+
const { AsyncResult } = await import("effect/reactivity");
12+
return {
13+
useAtomCommand: (() => async () =>
14+
AsyncResult.failure(
15+
Cause.fail(new PullRequestOperationError({ operation: "runAction", detail: state.detail })),
16+
)) as never,
17+
};
18+
});
19+
20+
import "~/index.css";
21+
import { render } from "../../../test/render";
22+
import { ToastProvider } from "../ui/toast";
23+
import { PullRequestStackMenu } from "./PullRequestStackMenu";
24+
25+
function setup(detail: string) {
26+
state.detail = detail;
27+
}
28+
29+
const HEAD_MOVED = "The stack head moved. Refresh the stack before trying again.";
30+
31+
it.each([
32+
{ label: "Merge stack", detail: HEAD_MOVED, description: HEAD_MOVED },
33+
{ label: "Rebase stack", detail: HEAD_MOVED, description: HEAD_MOVED },
34+
{
35+
label: "Rebase stack",
36+
detail: "GitHub CLI command failed.",
37+
description:
38+
"The host refused the rebase. A rebase stops at the first commit that does not apply cleanly.",
39+
},
40+
])("$label refused with $detail shows $description", async (row) => {
41+
setup(row.detail);
42+
await using screen = await render(
43+
<ToastProvider>
44+
<PullRequestStackMenu
45+
environmentId={EnvironmentId.make("environment")}
46+
reference={{
47+
projectId: ProjectId.make("project"),
48+
repository: "owner/repository",
49+
number: 2,
50+
}}
51+
hostLabel="GitHub"
52+
terminology={sourceControlClients.get("github").changeRequest}
53+
stack={{
54+
id: "stack",
55+
number: 1,
56+
url: "https://github.com/owner/repository/stack/1",
57+
base: "main",
58+
layers: [{ number: 2, headBranch: "feature", headSha: "abc123", state: "open" }],
59+
}}
60+
canMerge
61+
canRebase
62+
mergeMethod="squash"
63+
onActed={() => {}}
64+
/>
65+
</ToastProvider>,
66+
);
67+
if (row.label === "Rebase stack") {
68+
await screen.getByRole("button", { name: "Stack 1, layer 1 of 1" }).click();
69+
await page.getByRole("menuitem", { name: row.label }).click();
70+
} else {
71+
await screen.getByRole("button", { name: row.label, exact: true }).click();
72+
}
73+
await page.getByRole("dialog").getByRole("button", { name: row.label, exact: true }).click();
74+
await expect.element(page.getByText(row.description, { exact: true })).toBeInTheDocument();
75+
});

‎apps/web/src/components/pullRequest/PullRequestStackMenu.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { PullRequestStackLayers } from "./PullRequestStackLayers";
2727
import { PullRequestStackHeader } from "./PullRequestStackHeader";
2828
import { PullRequestStackLayerContent } from "./PullRequestStackLayerContent";
2929
import { PullRequestGlyph } from "./pullRequestIcons";
30+
import { readableFailure } from "./pullRequestDetail.logic";
3031

3132
export function PullRequestStackMenu({
3233
hostLabel,
@@ -114,7 +115,12 @@ export function PullRequestStackMenu({
114115
toastManager.update(toastId, {
115116
type: "error",
116117
title: action === "merge" ? "Could not merge the stack" : "Could not rebase the stack",
117-
description: String(squashAtomCommandFailure(result)),
118+
description: readableFailure(
119+
squashAtomCommandFailure(result),
120+
action === "merge"
121+
? "The host refused the merge. Check that you have write access, that the checks it requires have passed, and that the branch is not conflicting."
122+
: "The host refused the rebase. A rebase stops at the first commit that does not apply cleanly.",
123+
),
118124
});
119125
} else {
120126
toastManager.update(toastId, {

0 commit comments

Comments
 (0)