Skip to content
TypeScript

fix(web): links to issues no longer strand the pull request viewer (#14242)

oliver7bc161f8692d
diff --git a/apps/server/src/pullRequest/AzureDevOpsPullRequestProvider.ts b/apps/server/src/pullRequest/AzureDevOpsPullRequestProvider.ts
index b11ba6e2056..2cdf78c56a1 100644
--- a/apps/server/src/pullRequest/AzureDevOpsPullRequestProvider.ts
+++ b/apps/server/src/pullRequest/AzureDevOpsPullRequestProvider.ts
@@ -117,6 +117,7 @@ export function azureDevOpsProviderFailure(
if (error._tag === "AzureDevOpsCliUnavailableError") return { reason: "missing-tool" };
if (error._tag === "AzureDevOpsCliAuthenticationError") return { reason: "unauthenticated" };
if (error._tag === "AzureDevOpsCliRateLimitError") return { reason: "rate-limited" };
+ if (error._tag === "AzureDevOpsPullRequestNotFoundError") return { reason: "not-found" };
return { reason: "failed" };
}
diff --git a/apps/server/src/pullRequest/BitbucketPullRequestProvider.ts b/apps/server/src/pullRequest/BitbucketPullRequestProvider.ts
index e0ee4c0a85b..f553dfd13bc 100644
--- a/apps/server/src/pullRequest/BitbucketPullRequestProvider.ts
+++ b/apps/server/src/pullRequest/BitbucketPullRequestProvider.ts
@@ -82,6 +82,12 @@ export function bitbucketProviderFailure(
...(error.retryAt === undefined ? {} : { retryAt: error.retryAt }),
};
}
+ if (
+ (error._tag === "BitbucketResponseError" || error._tag === "BitbucketResponseBodyReadError") &&
+ error.status === 404
+ ) {
+ return { reason: "not-found" };
+ }
return { reason: "failed" };
}
diff --git a/apps/server/src/pullRequest/ForgejoPullRequestProvider.ts b/apps/server/src/pullRequest/ForgejoPullRequestProvider.ts
index 73d582c9042..12d931279a7 100644
--- a/apps/server/src/pullRequest/ForgejoPullRequestProvider.ts
+++ b/apps/server/src/pullRequest/ForgejoPullRequestProvider.ts
@@ -89,7 +89,9 @@ export const make = Effect.gen(function* () {
? "unauthenticated"
: error.reason === "rate-limit"
? "rate-limited"
- : "failed",
+ : error.reason === "not-found"
+ ? "not-found"
+ : "failed",
}),
),
);
diff --git a/apps/server/src/pullRequest/GitHubPullRequestProvider.ts b/apps/server/src/pullRequest/GitHubPullRequestProvider.ts
index 5e70c2ee1ed..a51825c2e11 100644
--- a/apps/server/src/pullRequest/GitHubPullRequestProvider.ts
+++ b/apps/server/src/pullRequest/GitHubPullRequestProvider.ts
@@ -115,6 +115,7 @@ export function gitHubProviderFailure(
if (error._tag === "SourceControlRateLimitPausedError") {
return { reason: "rate-limited", retryAt: error.retryAt };
}
+ if (error._tag === "GitHubPullRequestNotFoundError") return { reason: "not-found" };
return { reason: "failed" };
}
diff --git a/apps/server/src/pullRequest/GitLabPullRequestProvider.ts b/apps/server/src/pullRequest/GitLabPullRequestProvider.ts
index ad089382352..45034b84787 100644
--- a/apps/server/src/pullRequest/GitLabPullRequestProvider.ts
+++ b/apps/server/src/pullRequest/GitLabPullRequestProvider.ts
@@ -102,6 +102,7 @@ export function gitLabProviderFailure(
if (error._tag === "GitLabCliUnavailableError") return { reason: "missing-tool" };
if (error._tag === "GitLabCliAuthenticationError") return { reason: "unauthenticated" };
if (error._tag === "GitLabCliRateLimitError") return { reason: "rate-limited" };
+ if (error._tag === "GitLabMergeRequestNotFoundError") return { reason: "not-found" };
return { reason: "failed" };
}
diff --git a/apps/server/src/pullRequest/PullRequestProvider.ts b/apps/server/src/pullRequest/PullRequestProvider.ts
index cc370637c60..f13af63304d 100644
--- a/apps/server/src/pullRequest/PullRequestProvider.ts
+++ b/apps/server/src/pullRequest/PullRequestProvider.ts
@@ -52,7 +52,13 @@ export class PullRequestProviderError extends Schema.TaggedError<PullRequestProv
{
provider: SourceControlProviderKindSchema,
operation: Schema.String,
- reason: Schema.Literals(["missing-tool", "unauthenticated", "rate-limited", "failed"]),
+ reason: Schema.Literals([
+ "missing-tool",
+ "unauthenticated",
+ "rate-limited",
+ "not-found",
+ "failed",
+ ]),
detail: Schema.String,
retryAt: Schema.optional(Schema.Number),
cause: Schema.optional(Schema.Defect()),
diff --git a/apps/server/src/pullRequest/PullRequestService.test.ts b/apps/server/src/pullRequest/PullRequestService.test.ts
index 7415ae45bfa..9a6b98ec399 100644
--- a/apps/server/src/pullRequest/PullRequestService.test.ts
+++ b/apps/server/src/pullRequest/PullRequestService.test.ts
@@ -4815,6 +4815,33 @@ it.effect("does not let a still-cached detail overwrite a fresher linked summary
}),
);
+it.effect("tells the client when the host has no pull request under that number", () =>
+ Effect.gen(function* () {
+ const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 121 };
+ const service = yield* makeService({
+ projects: [project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" })],
+ providers: [
+ fakeProvider("github", {
+ getChangeRequest: () =>
+ Effect.fail(
+ new PullRequestProviderError({
+ provider: "github",
+ operation: "getChangeRequest",
+ reason: "not-found",
+ detail: "Pull request not found. Check the PR number or URL and try again.",
+ }),
+ ),
+ }),
+ ],
+ });
+
+ const error = yield* Effect.flip(service.detail(reference));
+
+ assert.strictEqual(error._tag, "PullRequestOperationError");
+ assert.strictEqual(error._tag === "PullRequestOperationError" && error.reason, "not-found");
+ }),
+);
+
it.effect("keeps recent detail on a transient refresh failure but not after invalidation", () =>
Effect.gen(function* () {
let failing = false;
diff --git a/apps/server/src/pullRequest/PullRequestService.ts b/apps/server/src/pullRequest/PullRequestService.ts
index 293318f91c4..ec523d39823 100644
--- a/apps/server/src/pullRequest/PullRequestService.ts
+++ b/apps/server/src/pullRequest/PullRequestService.ts
@@ -477,7 +477,12 @@ function toPullRequestError(
return (error) =>
isProviderUnusable(error)
? toUnavailableError(error)
- : new PullRequestOperationError({ operation, detail: error.detail, cause: error });
+ : new PullRequestOperationError({
+ operation,
+ detail: error.detail,
+ ...(error.reason === "not-found" ? { reason: "not-found" as const } : {}),
+ cause: error,
+ });
}
function withRateLimitBackoff(
diff --git a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
index 5c82e03aa8e..bf5bd62de91 100644
--- a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
+++ b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
@@ -144,6 +144,7 @@ import {
handoffReviewComments,
latestPullRequestReviewOutcomes,
loadingPullRequestCheckoutCommand,
+ isPullRequestNotFound,
isStackedPullRequestBase,
pullRequestActionMenuHasGroup,
pullRequestActionNeedsHostRefresh,
@@ -2719,7 +2720,13 @@ export function PullRequestDetailPanel({
>
{detailQuery.error && !detail ? (
<PullRequestsUnavailableState
- error={detailQuery.error}
+ {...(isPullRequestNotFound(detailQuery.failure)
+ ? {
+ title: `Pull request #${reference.number} not found`,
+ error:
+ "It may be an issue rather than a pull request, or this account can't see it.",
+ }
+ : { error: detailQuery.error })}
refreshing={detailQuery.isPending}
onRetry={refreshDetail}
{...(unavailableGitHubUrl ? { gitHubUrl: unavailableGitHubUrl } : {})}
diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
index b8d2d897a45..cdca896e607 100644
--- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
+++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
@@ -2,6 +2,7 @@ import * as Schema from "effect/Schema";
import {
PullRequestDetail,
+ PullRequestOperationError,
pullRequestHostOf,
type PullRequestAction,
type PullRequestActor,
@@ -1161,6 +1162,12 @@ export function buildAddSelectionToAgentHandoff(input: {
};
}
+const isPullRequestOperationError = Schema.is(PullRequestOperationError);
+
+export function isPullRequestNotFound(failure: unknown): boolean {
+ return isPullRequestOperationError(failure) && failure.reason === "not-found";
+}
+
/**
* The internal wrapper every failed operation arrives in: which operation ran, and which tool
* said no. A reader has no use for either.
diff --git a/apps/web/src/state/query.ts b/apps/web/src/state/query.ts
index ba081ffab1b..6a44c81049c 100644
--- a/apps/web/src/state/query.ts
+++ b/apps/web/src/state/query.ts
@@ -7,10 +7,11 @@ const EMPTY_ASYNC_RESULT_ATOM = Atom.make(AsyncResult.initial<never, never>(fals
Atom.withLabel("web-environment-query:empty"),
);
-export interface EnvironmentQueryView<A> {
+export interface EnvironmentQueryView<A, E = unknown> {
readonly data: A | null;
readonly dataUpdatedAt: number;
readonly error: string | null;
+ readonly failure: E | null;
readonly isPending: boolean;
readonly isSuccess: boolean;
readonly refresh: () => void;
@@ -25,7 +26,7 @@ export function formatEnvironmentQueryError(cause: Cause.Cause<unknown>): string
export function useEnvironmentQuery<A, E>(
atom: Atom.Atom<AsyncResult.AsyncResult<A, E>> | null,
-): EnvironmentQueryView<A> {
+): EnvironmentQueryView<A, E> {
const selectedAtom = atom ?? EMPTY_ASYNC_RESULT_ATOM;
const result = useAtomValue(selectedAtom);
const refresh = useAtomRefresh(selectedAtom);
@@ -38,6 +39,8 @@ export function useEnvironmentQuery<A, E>(
? (Option.getOrNull(result.previousSuccess)?.timestamp ?? 0)
: 0,
error: result._tag === "Failure" ? formatEnvironmentQueryError(result.cause) : null,
+ failure:
+ result._tag === "Failure" ? Option.getOrNull(Cause.findErrorOption(result.cause)) : null,
isPending: atom !== null && result.waiting,
isSuccess: result._tag === "Success",
refresh,
diff --git a/packages/contracts/src/pullRequest.ts b/packages/contracts/src/pullRequest.ts
index c8feaad9a41..b17d0141dae 100644
--- a/packages/contracts/src/pullRequest.ts
+++ b/packages/contracts/src/pullRequest.ts
@@ -1407,6 +1407,7 @@ export class PullRequestOperationError extends Schema.TaggedError<PullRequestOpe
{
operation: Schema.String,
detail: TrimmedNonEmptyString,
+ reason: Schema.optional(Schema.Literal("not-found")),
cause: Schema.optional(Schema.Defect()),
},
{ httpApiStatus: 502 },