diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index a71bc0d2db367..4fd39e8169bda 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -989,6 +989,9 @@ describe("what to say when an action fails", () => { const reason = "The worktree directory already exists. Choose another directory."; expect(checkoutFailureDescription(diagnostic(reason))).toBe(reason); expect(checkoutFailureDescription(diagnostic("x".repeat(900)))).toBe(`${"x".repeat(319)}…`); + expect(checkoutFailureDescription(diagnostic(`${"x".repeat(318)}😀 tail`))).toBe( + `${"x".repeat(318)}…`, + ); for (const failure of [undefined, diagnostic(""), diagnostic("exited with code 1")]) { expect(checkoutFailureDescription(failure)).toBe( "Check that the branch still exists and is not checked out elsewhere, then try again.", diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index ad9285f6fc322..e69fd93773e89 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -1569,11 +1569,11 @@ export function readableFailure(failure: unknown, hint: string): string { failure instanceof Error ? failure.message : typeof failure === "string" ? failure : ""; const detail = raw.replace(OPERATION_PREFIX, "").trim(); if (detail.length === 0 || TOOL_NOISE.some((pattern) => pattern.test(detail))) return hint; - const bounded = - detail.length <= FAILURE_DETAIL_MAX_LENGTH - ? detail - : `${detail.slice(0, FAILURE_DETAIL_MAX_LENGTH - 1)}…`; - return bounded; + if (detail.length <= FAILURE_DETAIL_MAX_LENGTH) return detail; + let end = FAILURE_DETAIL_MAX_LENGTH - 1; + const last = detail.charCodeAt(end - 1); + if (last >= 0xd800 && last <= 0xdbff) end -= 1; + return `${detail.slice(0, end)}…`; } const isGitCommandError = Schema.is(GitCommandError);