mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* fix(cli): a failed command sends one cli_error, naming its real cause * chore(cli): drop a comment the parameter name already says * fix(cli): a failure caught by its own command is still reported, and only once * test(cli): normalize-audio test passes the flags it requires * style(cli): format the failure tracking test * fix(cli): one function unwraps and reports a command failure, once * docs(cli): shorten the command failure reporter's comment
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { failCommand } from "../../utils/commandResult.js";
|
|
/**
|
|
* Shared CLI error boundary for `hyperframes figma` subcommands: typed
|
|
* client errors (NO_TOKEN, BAD_TOKEN, …) and input errors (bad ref, bad
|
|
* format) all carry actionable, user-facing messages — present them via
|
|
* the CLI's standard errorBox, not a stack trace. Non-Error throws still
|
|
* surface raw.
|
|
*
|
|
* It reports inline to name the typed code (FigmaClientError code) — the whole
|
|
* first-run funnel: NO_TOKEN → later success is onboarding conversion.
|
|
*/
|
|
|
|
import { FigmaClientError } from "@hyperframes/core/figma";
|
|
import { errorBox } from "../../ui/format.js";
|
|
|
|
export async function withFigmaErrors(command: string, fn: () => Promise<void>): Promise<void> {
|
|
try {
|
|
await fn();
|
|
} catch (err) {
|
|
if (err instanceof Error) {
|
|
try {
|
|
const { trackCommandFailure } = await import("../../telemetry/events.js");
|
|
// Surface the typed code (NO_TOKEN, BAD_TOKEN, RATE_LIMITED, …) as the
|
|
// error name — `FigmaClientError` alone says nothing in a dashboard.
|
|
trackCommandFailure(
|
|
command,
|
|
err,
|
|
err instanceof FigmaClientError ? { error_name: err.code, endpoint: err.endpoint } : {},
|
|
);
|
|
} catch {
|
|
// Telemetry must never mask the real command failure.
|
|
}
|
|
const [title = "figma command failed", ...rest] = err.message.split("\n");
|
|
errorBox(title, rest.length > 0 ? rest.join("\n") : undefined);
|
|
failCommand(1, err);
|
|
}
|
|
throw err;
|
|
}
|
|
}
|