fix(core,cli): attribute figma REST failures to the endpoint that failed

cli_error had no way to tell which figma REST call (images, files_nodes,
variables_local, styles, ...) actually hit RATE_LIMITED/FORBIDDEN/etc, so
the dashboard could see failures spike but not which call caused them.

FigmaClientError now carries a low-cardinality endpoint label (never the
raw fileKey/nodeId), threaded through to cli_error's endpoint property.
This commit is contained in:
Vance Ingalls
2026-07-13 21:41:55 +00:00
parent 9b71bc2103
commit 4ca1552e20
5 changed files with 103 additions and 5 deletions
@@ -29,6 +29,7 @@ export async function withFigmaErrors(command: string, fn: () => Promise<void>):
stack_trace: err.stack,
command,
kind: "command_error",
endpoint: err instanceof FigmaClientError ? err.endpoint : undefined,
});
await telemetry.flush();
} catch {
+15
View File
@@ -431,6 +431,21 @@ describe("trackCliError", () => {
expect(props.error_message).toContain("[path]");
expect(props.stack_trace).not.toContain("/Users/alice");
});
it("forwards the figma endpoint label when supplied", () => {
trackCliError({
error_name: "RATE_LIMITED",
error_message: "figma rate limit hit (429)",
command: "figma asset",
kind: "command_error",
endpoint: "images",
});
expect(trackEvent).toHaveBeenCalledWith(
"cli_error",
expect.objectContaining({ endpoint: "images" }),
);
});
});
describe("trackCommandFailure", () => {
+4
View File
@@ -490,6 +490,9 @@ export function trackCliError(props: {
stack_trace?: string;
command?: string;
kind: "uncaught_exception" | "unhandled_rejection" | "command_error";
/** Low-cardinality figma REST call label (e.g. "images", "files_nodes") —
* which endpoint failed, for FigmaClientError-backed failures only. */
endpoint?: string;
}): void {
trackEvent("cli_error", {
error_name: props.error_name,
@@ -502,6 +505,7 @@ export function trackCliError(props: {
: undefined,
command: props.command,
kind: props.kind,
endpoint: props.endpoint,
});
}