Skip to content

Commit 2d6d555

Browse files
committed
fix(pr): improve error visibility, pagination bounds, and UI consistency
- Log stderr from gh pr view instead of silently returning undefined (anomalyco#10) - Cap pr-comments pagination at 10 pages to prevent runaway requests (anomalyco#18) - Use resolveApiErrorMessage in delete-branch dialog for consistent error UX (anomalyco#19) - Default remoteBranchExists to false while loading to avoid UI flash (anomalyco#20)
1 parent 0731d65 commit 2d6d555

4 files changed

Lines changed: 20 additions & 7 deletions

File tree

‎packages/app/src/components/dialog-delete-branch.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { createStore } from "solid-js/store"
88
import { useLanguage } from "@/context/language"
99
import { useSDK } from "@/context/sdk"
1010
import { useSync } from "@/context/sync"
11+
import { resolveApiErrorMessage } from "@/utils/pr-errors"
1112

1213
export function DeleteBranchDialog() {
1314
const dialog = useDialog()
@@ -39,11 +40,13 @@ export function DeleteBranchDialog() {
3940
title: language.t("pr.toast.branch_deleted"),
4041
})
4142
dialog.close()
42-
} catch {
43+
} catch (e: unknown) {
4344
showToast({
4445
variant: "error",
4546
icon: "circle-x",
46-
title: language.t("pr.error.delete_branch_failed"),
47+
title: resolveApiErrorMessage(e, language.t("pr.error.delete_branch_failed"), (k) =>
48+
language.t(k as Parameters<typeof language.t>[0]),
49+
),
4750
})
4851
} finally {
4952
setStore("submitting", false)

‎packages/app/src/components/pr-button.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function PrButton() {
7070
const remoteBranchExists = createMemo(() => {
7171
const branchName = pr()?.headRefName
7272
const branches = vcs()?.branches
73-
if (!branchName || !branches) return true
73+
if (!branchName || !branches) return false
7474
return branches.includes(branchName)
7575
})
7676

‎packages/opencode/src/project/pr-comments.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,14 @@ export namespace PrComments {
9090

9191
const allThreads: ReviewThread[] = []
9292
let cursor: string | null = null
93+
const MAX_PAGES = 10
94+
let page = 0
9395

9496
do {
97+
if (++page > MAX_PAGES) {
98+
log.warn("pr-comments: max pages reached, truncating")
99+
break
100+
}
95101
const query = buildQuery()
96102
const args = [
97103
"gh",

‎packages/opencode/src/project/pr.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,19 @@ export namespace PR {
8585
export async function fetchForBranch(repo?: { owner: string; name: string }): Promise<Vcs.PrInfo | undefined> {
8686
const cwd = Instance.worktree
8787
try {
88-
const result = await withTimeout(
88+
const cmd = await withTimeout(
8989
$`gh pr view --json number,url,title,state,headRefName,baseRefName,isDraft,mergeable,reviewDecision,statusCheckRollup`
9090
.quiet()
9191
.nothrow()
92-
.cwd(cwd)
93-
.text(),
92+
.cwd(cwd),
9493
30_000,
9594
)
96-
if (!result.trim()) {
95+
if (cmd.exitCode !== 0) {
96+
log.warn("gh pr view failed", { stderr: cmd.stderr.toString().trim() })
97+
return undefined
98+
}
99+
const result = cmd.stdout.toString().trim()
100+
if (!result) {
97101
return undefined
98102
}
99103
const parsed = JSON.parse(result)

0 commit comments

Comments
 (0)