fix(cli): keep sharing owner error codes stable

This commit is contained in:
Terence Cho
2026-11-10 10:20:01 -08:00
parent 2187bdf302
commit 8756c2d17d
5 changed files with 35 additions and 5 deletions
+4
View File
@@ -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
+1 -1
View File
@@ -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.",
);
+20
View File
@@ -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.`,
},
});
},
);
+4 -1
View File
@@ -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);
}
+6 -3
View File
@@ -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<string, string> = {
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.",