mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
Merge pull request #2358 from heygen-com/07-13-fix_core_cli_attribute_figma_rest_failures_to_the_endpoint_that_failed
fix(core,cli): attribute figma REST failures to the endpoint that failed
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
runAssetImportMany,
|
||||
type AssetImportDeps,
|
||||
} from "./asset.js";
|
||||
import type { FigmaClient } from "@hyperframes/core/figma";
|
||||
import { FigmaClientError, type FigmaClient } from "@hyperframes/core/figma";
|
||||
|
||||
const dirs: string[] = [];
|
||||
function scratch(): string {
|
||||
@@ -179,6 +179,24 @@ describe("runAssetImport", () => {
|
||||
expect(new Set(results.map((r) => r.record.id)).size).toBe(3);
|
||||
});
|
||||
|
||||
it("labels a batch-miss RENDER_FAILED with the images endpoint (telemetry parity with client.ts)", async () => {
|
||||
const dir = scratch();
|
||||
const missClient = fakeClient({
|
||||
renderNodes: (fileKey, nodeIds) =>
|
||||
Promise.resolve(nodeIds.map((nodeId) => ({ nodeId, url: null, ext: "png" }))),
|
||||
});
|
||||
const err = await runAssetImportMany(
|
||||
["KEY:1-2"],
|
||||
{ format: "png" },
|
||||
deps(dir, { client: missClient }),
|
||||
).catch((e: unknown) => e);
|
||||
expect(err).toBeInstanceOf(FigmaClientError);
|
||||
if (err instanceof FigmaClientError) {
|
||||
expect(err.code).toBe("RENDER_FAILED");
|
||||
expect(err.endpoint).toBe("images");
|
||||
}
|
||||
});
|
||||
|
||||
it("gatherAssetRefs splits bare comma-joined ids but keeps URLs whole", () => {
|
||||
// bare tokens comma-split
|
||||
expect(gatherAssetRefs(["KEY:1-2,KEY:3-4"])).toEqual(["KEY:1-2", "KEY:3-4"]);
|
||||
|
||||
@@ -209,6 +209,8 @@ export async function runAssetImportMany(
|
||||
throw new FigmaClientError(
|
||||
"RENDER_FAILED",
|
||||
`figma could not render node ${nodeId} as ${opts.format}`,
|
||||
undefined,
|
||||
"images",
|
||||
);
|
||||
slots[i] = await freezeAndRecord(
|
||||
fileKey,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user