From 8756c2d17d7c1934c79c6b8ff09d030ff638e20f Mon Sep 17 00:00:00 2001 From: Terence Cho Date: Tue, 10 Nov 2026 10:20:01 -0800 Subject: [PATCH] fix(cli): keep sharing owner error codes stable --- docs/packages/cli.mdx | 4 ++++ packages/cli/src/auth/errors.ts | 2 +- packages/cli/src/commands/share.test.ts | 20 ++++++++++++++++++++ packages/cli/src/commands/share.ts | 5 ++++- packages/cli/src/share/errors.ts | 9 ++++++--- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/docs/packages/cli.mdx b/docs/packages/cli.mdx index b38858540d..43d6ad2441 100644 --- a/docs/packages/cli.mdx +++ b/docs/packages/cli.mdx @@ -3094,6 +3094,10 @@ failed update; `url` remains null. Use `--update` to explicitly retry with the current project. Signing into a different account while a share is running stops that operation; start it again after sign-in. +When another account owns the review, JSON errors use the fixed code +`owner_signed_out` with the owner email in `error.owner`. The human-readable +message also identifies the account to sign into. + The standard production CLI includes exact trusted storage origins for review videos and editable project sources; no upload configuration is required. Development environments, custom API/OAuth endpoints or clients, and custom diff --git a/packages/cli/src/auth/errors.ts b/packages/cli/src/auth/errors.ts index de229d270e..c1a2a33643 100644 --- a/packages/cli/src/auth/errors.ts +++ b/packages/cli/src/auth/errors.ts @@ -37,7 +37,7 @@ export class AuthError extends Error { export const ErrNotConfigured = () => new AuthError( "NOT_CONFIGURED", - "No HeyGen credentials found", + "No HeyGen credentials found.", "Run `hyperframes auth login` to sign in.", ); diff --git a/packages/cli/src/commands/share.test.ts b/packages/cli/src/commands/share.test.ts index 42c8999aad..4fb1e69df9 100644 --- a/packages/cli/src/commands/share.test.ts +++ b/packages/cli/src/commands/share.test.ts @@ -1,3 +1,4 @@ +import { ReviewFailed } from "@hyperframes/share"; import { afterEach, beforeEach, expect, it, vi } from "vitest"; import { runCommand } from "citty"; import { consumeCommandResult } from "../utils/commandResult.js"; @@ -96,3 +97,22 @@ it("deduplicates progress and terminates each message before the friendly error" ]); expect(friendly).toHaveBeenCalledWith("Sharing blocked."); }); + +it.each(["owner@example.com", "another@example.com"])( + "keeps the owner error code stable for %s", + async (owner) => { + mocks.run.mockRejectedValue(new ReviewFailed(403, `owner_signed_out:${owner}`)); + const out = vi.spyOn(console, "log").mockImplementation(() => {}); + await runCommand(command, { rawArgs: ["--status", "--json"] }); + expect(consumeCommandResult().exitCode).toBe(1); + expect(out).toHaveBeenCalledOnce(); + expect(JSON.parse(String(out.mock.calls[0]?.[0]))).toEqual({ + ok: false, + error: { + code: "owner_signed_out", + owner, + message: `This review belongs to ${owner}. Switch to that account to manage it.`, + }, + }); + }, +); diff --git a/packages/cli/src/commands/share.ts b/packages/cli/src/commands/share.ts index 13a0f3b339..59894ecb75 100644 --- a/packages/cli/src/commands/share.ts +++ b/packages/cli/src/commands/share.ts @@ -73,7 +73,10 @@ export default defineCommand({ await presentResult(result, input, Boolean(args.json)); } catch (error) { const failure = shareError(error); - if (args.json) console.log(JSON.stringify(jsonFailure(failure.code, failure.message))); + if (args.json) + console.log( + JSON.stringify({ ...jsonFailure(failure.code, failure.message), error: failure }), + ); else console.error(failure.message); setCommandExitCode(error instanceof CliUsageError ? 2 : 1); } diff --git a/packages/cli/src/share/errors.ts b/packages/cli/src/share/errors.ts index 5a662c8089..21d8a878d4 100644 --- a/packages/cli/src/share/errors.ts +++ b/packages/cli/src/share/errors.ts @@ -1,4 +1,4 @@ -import { ReviewFailed, reviewSentence } from "@hyperframes/share"; +import { ownerOf, ReviewFailed, reviewSentence } from "@hyperframes/share"; import { ShareSourceError } from "./sources.js"; import { isAuthError } from "../auth/errors.js"; import { CliUsageError } from "../utils/commandResult.js"; @@ -19,7 +19,7 @@ const HINTS: Record = { not_shared: "This project has no shared review yet. Run hyperframes share with an explicit audience.", }; -export function shareError(error: unknown): { code: string; message: string } { +export function shareError(error: unknown): { code: string; message: string; owner?: string } { if (error instanceof CliUsageError) return { code: error.code, message: error.message }; if (error instanceof ShareSourceError) return { code: "source_unavailable", message: error.message }; @@ -28,11 +28,14 @@ export function shareError(error: unknown): { code: string; message: string } { code: error.code.toLowerCase(), message: `${error.message} ${error.hint ?? ""}`.trim(), }; - if (error instanceof ReviewFailed) + if (error instanceof ReviewFailed) { + const owner = error.status === 401 ? null : ownerOf(error.reason); + if (owner !== null) return { code: "owner_signed_out", owner, message: reviewSentence(error) }; return { code: error.status === 401 ? "login_expired" : error.reason || "share_failed", message: HINTS[error.reason] ?? reviewSentence(error), }; + } return { code: "share_failed", message: error instanceof Error ? error.message : "Sharing failed. Try again.",