Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

[codex] Structure pull request link failures (#3445)

Julius Marmingea9460bb772a8
diff --git a/apps/web/src/components/GitActionsControl.tsx b/apps/web/src/components/GitActionsControl.tsx
index af3f7b472..c98167194 100644
--- a/apps/web/src/components/GitActionsControl.tsx
+++ b/apps/web/src/components/GitActionsControl.tsx
@@ -88,6 +88,7 @@ import { resolvePathLinkTarget } from "~/terminal-links";
import { type DraftId, useComposerDraftStore } from "~/composerDraftStore";
import { readLocalApi } from "~/localApi";
import { getSourceControlPresentation } from "~/sourceControlPresentation";
+import { openPullRequestLink } from "~/lib/openPullRequestLink";
interface GitActionsControlProps {
gitCwd: string | null;
@@ -1229,7 +1230,8 @@ export default function GitActionsControl({
});
return;
}
- void api.shell.openExternal(prUrl).catch((err: unknown) => {
+ void openPullRequestLink(api.shell, prUrl).catch((err: unknown) => {
+ console.error(err);
toastManager.add(
stackedThreadToast({
type: "error",
diff --git a/apps/web/src/lib/openPullRequestLink.test.ts b/apps/web/src/lib/openPullRequestLink.test.ts
new file mode 100644
index 000000000..756e1ed6a
--- /dev/null
+++ b/apps/web/src/lib/openPullRequestLink.test.ts
@@ -0,0 +1,30 @@
+import { describe, expect, it, vi } from "vite-plus/test";
+
+import { openPullRequestLink, PullRequestLinkOpenError } from "./openPullRequestLink";
+
+describe("openPullRequestLink", () => {
+ it("opens the requested pull request URL", async () => {
+ const openExternal = vi.fn(async () => undefined);
+ const targetUrl = "https://github.com/pingdotgg/t3code/pull/123";
+
+ await openPullRequestLink({ openExternal }, targetUrl);
+
+ expect(openExternal).toHaveBeenCalledExactlyOnceWith(targetUrl);
+ });
+
+ it("reports bridge failures with a safe target origin", async () => {
+ const cause = new Error("desktop shell unavailable");
+ const targetUrl = "https://github.com/pingdotgg/t3code/pull/123?token=secret";
+ const openExternal = vi.fn(async () => Promise.reject(cause));
+
+ const result = openPullRequestLink({ openExternal }, targetUrl);
+
+ await expect(result).rejects.toEqual(
+ new PullRequestLinkOpenError({
+ targetOrigin: "https://github.com",
+ cause,
+ }),
+ );
+ await expect(result).rejects.not.toHaveProperty("message", expect.stringContaining("secret"));
+ });
+});
diff --git a/apps/web/src/lib/openPullRequestLink.ts b/apps/web/src/lib/openPullRequestLink.ts
index 899e5c38c..acd3c5a06 100644
--- a/apps/web/src/lib/openPullRequestLink.ts
+++ b/apps/web/src/lib/openPullRequestLink.ts
@@ -1,8 +1,45 @@
+import type { LocalApi } from "@t3tools/contracts";
+import * as Schema from "effect/Schema";
import { type MouseEvent, useCallback } from "react";
import { stackedThreadToast, toastManager } from "../components/ui/toast";
import { readLocalApi } from "../localApi";
+export class PullRequestLinkOpenError extends Schema.TaggedErrorClass<PullRequestLinkOpenError>()(
+ "PullRequestLinkOpenError",
+ {
+ targetOrigin: Schema.NullOr(Schema.String),
+ cause: Schema.Defect(),
+ },
+) {
+ static fromCause(targetUrl: string, cause: unknown): PullRequestLinkOpenError {
+ let targetOrigin: string | null = null;
+ try {
+ targetOrigin = new URL(targetUrl).origin;
+ } catch {
+ // Keep malformed URLs out of diagnostics while preserving the open failure below.
+ }
+ return new PullRequestLinkOpenError({ targetOrigin, cause });
+ }
+
+ override get message(): string {
+ return this.targetOrigin === null
+ ? "Unable to open pull request link."
+ : `Unable to open pull request link at ${this.targetOrigin}.`;
+ }
+}
+
+export async function openPullRequestLink(
+ shell: Pick<LocalApi["shell"], "openExternal">,
+ targetUrl: string,
+): Promise<void> {
+ try {
+ await shell.openExternal(targetUrl);
+ } catch (cause) {
+ throw PullRequestLinkOpenError.fromCause(targetUrl, cause);
+ }
+}
+
/**
* Returns a click handler that opens a pull request URL in the system browser.
*
@@ -24,7 +61,8 @@ export function useOpenPrLink() {
return;
}
- void api.shell.openExternal(prUrl).catch((error) => {
+ void openPullRequestLink(api.shell, prUrl).catch((error) => {
+ console.error(error);
toastManager.add(
stackedThreadToast({
type: "error",