mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
fix(studio): error events send a class, a shape and Studio's own frames, not the error's words (#8114)
* fix(studio): error events send a class, a shape and Studio's own frames, not the error's words Error messages from the browser, a server or the project now leave as an unsalted shape of the cut first line (numbers, quotes and paths removed) plus any HTTP status, beside the error class each sender now passes. Stacks keep only frames in Studio's own scripts as fn@file:line:col; any other frame, its name included, is ?. Component stacks keep component names. A script filename is sent only when it is one of Studio's own. The resolver shadow's mismatch list no longer carries the error's words or the selector-built animation id. * fix(studio): error shapes match across projects and bare paths are never Studio frames Only an absolute http(s) frame on Studio's origin is kept; the message shape cuts URLs and selector ids and uses the install salt.
This commit is contained in:
@@ -118,7 +118,10 @@ export function useCaptionSync(projectId: string | null) {
|
||||
.catch((error: unknown) => {
|
||||
// Caption auto-save is a data-loss path: surface it to the user, not
|
||||
// just telemetry. pendingRef stays true so beforeunload still warns.
|
||||
trackEvent("studio_caption_autosave_failed", { error: String(error) });
|
||||
trackEvent("studio_caption_autosave_failed", {
|
||||
error_name: error instanceof Error ? error.name : typeof error,
|
||||
error: String(error),
|
||||
});
|
||||
useCaptionStore.getState().setSyncError(held ?? "Caption changes couldn't be saved");
|
||||
});
|
||||
}, []);
|
||||
|
||||
@@ -797,6 +797,7 @@ describe("useSdkSession unavailable telemetry", () => {
|
||||
expect(trackMock).toHaveBeenCalledWith("sdk_session_unavailable", {
|
||||
stage: "open",
|
||||
error: "unparseable composition",
|
||||
error_name: "Error",
|
||||
});
|
||||
await act(async () => root.unmount());
|
||||
});
|
||||
|
||||
@@ -342,6 +342,7 @@ function disposeSdkSession(session: Composition): void {
|
||||
session.dispose();
|
||||
} catch (error) {
|
||||
trackStudioEvent("sdk_session_dispose_failed", {
|
||||
error_name: error instanceof Error ? error.name : typeof error,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
});
|
||||
}
|
||||
@@ -510,6 +511,7 @@ export function useSdkSession(
|
||||
// bucket was a network error wearing a parser's label.
|
||||
trackStudioEvent("sdk_session_unavailable", {
|
||||
stage: "open",
|
||||
error_name: error instanceof Error ? error.name : typeof error,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -82,8 +82,9 @@ describe("Studio analytics leave the machine without paths or selectors", () =>
|
||||
selector_kind: "attribute",
|
||||
target_id_kind: "id",
|
||||
status_code: 403,
|
||||
dropped_fields: "detail,error_message",
|
||||
dropped_fields: "detail",
|
||||
});
|
||||
expect(first?.error_message_shape).toMatch(/^[0-9a-f]{8}$/);
|
||||
expect(first?.file_path_hash).toMatch(/^[0-9a-f]{8}$/);
|
||||
// The same path from the same install groups; the salt that keys it never leaves.
|
||||
expect(second?.file_path_hash).toBe(first?.file_path_hash);
|
||||
@@ -100,6 +101,51 @@ describe("Studio analytics leave the machine without paths or selectors", () =>
|
||||
expect(batch[0]?.properties.tab_id).not.toBe("custom");
|
||||
});
|
||||
|
||||
const PROJECT_FRAME =
|
||||
"http://localhost:3002/api/projects/acme-launch/preview/compositions/intro.html:12:3";
|
||||
const STACK = [
|
||||
"Error: Failed to save compositions/intro.html (403): forbidden path: /Users/ana/客户/x.html",
|
||||
` at mountClip (${PROJECT_FRAME})`,
|
||||
` at commitEdit (${location.origin}/assets/index-B4x2.js:40:7)`,
|
||||
` at ${location.origin}/assets/vendor-C9.js:1:99`,
|
||||
].join("\n");
|
||||
const LEAKS = ["acme-launch", "intro.html", "客户", "/Users/ana", "forbidden path", "mountClip"];
|
||||
|
||||
it.each(["studio:*", "studio_*"] as const)(
|
||||
"the %s transport sends an error's class, a shape and its own frames, never its words",
|
||||
async (transport) => {
|
||||
await send(transport, "crash", {
|
||||
error_message:
|
||||
"Failed to save compositions/intro.html (403): forbidden path: /Users/ana/客户/x.html",
|
||||
error_name: "StudioSaveHttpError",
|
||||
stack_trace: STACK,
|
||||
component_stack: `\n at ClipRow (${PROJECT_FRAME})\n at Timeline (${location.origin}/assets/index-B4x2.js:9:1)`,
|
||||
});
|
||||
await send(transport, "unhandled_promise_rejection", {
|
||||
error_message: "acme-launch secret",
|
||||
error_name: null,
|
||||
stack_trace: null,
|
||||
});
|
||||
await send(transport, "unhandled_error", {
|
||||
error: "x",
|
||||
filename: PROJECT_FRAME.replace(/:\d+:\d+$/, ""),
|
||||
});
|
||||
const { body, batch } = await sent();
|
||||
|
||||
for (const text of LEAKS) expect(body).not.toContain(text);
|
||||
const [crash, rejection, uncaught] = batch.map((e) => e.properties);
|
||||
expect(crash).toMatchObject({
|
||||
error_name: "StudioSaveHttpError",
|
||||
error_message_status: 403,
|
||||
stack_trace: "?\ncommitEdit@index-B4x2.js:40:7\n<anonymous>@vendor-C9.js:1:99",
|
||||
component_stack: "ClipRow\nTimeline",
|
||||
});
|
||||
expect(crash?.error_message_shape).toMatch(/^[0-9a-f]{8}$/);
|
||||
expect(rejection?.error_message_shape).toMatch(/^[0-9a-f]{8}$/);
|
||||
expect(uncaught?.dropped_fields).toBe("filename");
|
||||
},
|
||||
);
|
||||
|
||||
it("leaves feedback text the person typed to send", async () => {
|
||||
await send("studio_*", "studio_feedback", {
|
||||
comment: "export of compositions/intro.html froze",
|
||||
@@ -108,3 +154,36 @@ describe("Studio analytics leave the machine without paths or selectors", () =>
|
||||
expect(batch[0]?.properties.comment).toBe("export of compositions/intro.html froze");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors leave no project name, even shaped", () => {
|
||||
const shape = async (properties: Record<string, string>) =>
|
||||
(await import("./eventShape")).shapeEventProperties("studio:crash", properties);
|
||||
|
||||
it("keeps only frames with an absolute address on Studio's own origin", async () => {
|
||||
const shaped = await shape({
|
||||
stack_trace: [
|
||||
"Error: acme-launch@acme-launch.js:1:2",
|
||||
" at secretHandler (/home/ana/acme-launch/server.js:10:5)",
|
||||
" at secretHandler (acme-launch-intro.js:10:5)",
|
||||
].join("\n"),
|
||||
filename: "acme-launch.js",
|
||||
});
|
||||
expect(JSON.stringify(shaped)).not.toMatch(/acme|secretHandler/);
|
||||
expect(shaped.dropped_fields).toBe("filename");
|
||||
});
|
||||
|
||||
it("gives two projects' same failure the same shape", async () => {
|
||||
const pairs = [
|
||||
["acme-launch", "other-proj"].map(
|
||||
(name) =>
|
||||
`Failed to fetch dynamically imported module: http://localhost/api/projects/${name}/preview/x.js`,
|
||||
),
|
||||
["#acme-title", "#other-title"].map((id) => `GSAP target ${id} not found.`),
|
||||
];
|
||||
for (const [a, b] of pairs) {
|
||||
expect((await shape({ error_message: a! })).error_message_shape).toBe(
|
||||
(await shape({ error_message: b! })).error_message_shape,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,9 +14,9 @@ const PATH_KEYS = new Set([
|
||||
"path",
|
||||
"composition",
|
||||
"render_composition",
|
||||
"filename",
|
||||
]);
|
||||
const SELECTOR_KEYS = new Set(["target_selector", "selector", "target_id", "animationId"]);
|
||||
const MESSAGE_KEYS = new Set(["error_message", "error", "render_error", "render_stage"]);
|
||||
// Text the person typed to send to us on purpose.
|
||||
const KEPT_AS_TYPED: Record<string, ReadonlySet<string>> = {
|
||||
studio_feedback: new Set(["comment"]),
|
||||
@@ -96,6 +96,52 @@ function selectorFacts(key: string, value: string): Facts {
|
||||
return { [`${key}_kind`]: kind, [`${key}_hash`]: hashOf(s) };
|
||||
}
|
||||
|
||||
function messageFacts(key: string, value: string): Facts {
|
||||
const line = redactTelemetryString(value.split("\n", 1)[0] ?? "", Number.MAX_SAFE_INTEGER)
|
||||
.replace(/\b(?:https?|blob|data|file|[a-z-]+-extension):\S*/gi, "<url>")
|
||||
.replace(/(^|[\s(])[#.][A-Za-z_][\w-]*/g, "$1<sel>")
|
||||
.replace(/(["'`]).*?\1/g, "?")
|
||||
.replace(/\d+/g, "#");
|
||||
const status = /(?:\(|HTTP |status |failed: )([1-5]\d\d)\b/.exec(value)?.[1];
|
||||
return {
|
||||
[`${key}_shape`]: hashOf(line),
|
||||
...(status ? { [`${key}_status`]: Number(status) } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function bundleFile(url: string): string | null {
|
||||
if (!/^https?:\/\//i.test(url)) return null;
|
||||
try {
|
||||
const at = new URL(url);
|
||||
if (at.origin !== location.origin || at.pathname.startsWith("/api/")) return null;
|
||||
const name = at.pathname.split("/").pop() ?? "";
|
||||
return /^[\w.-]+\.(?:m?js|tsx?|jsx?)$/.test(name) ? name : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const V8_FRAME = /^\s*at (?:(.+?) \()?(.+?):(\d+):(\d+)\)?\s*$/;
|
||||
const GECKO_FRAME = /^(.*?)@(.+?):(\d+):(\d+)\s*$/;
|
||||
|
||||
function shapedFrames(stack: string): string {
|
||||
const frames: string[] = [];
|
||||
for (const line of stack.split("\n")) {
|
||||
const m = V8_FRAME.exec(line) ?? GECKO_FRAME.exec(line);
|
||||
if (!m) continue;
|
||||
const file = bundleFile(m[2] ?? "");
|
||||
frames.push(file ? `${m[1]?.trim() || "<anonymous>"}@${file}:${m[3]}:${m[4]}` : "?");
|
||||
if (frames.length === 20) break;
|
||||
}
|
||||
return frames.join("\n");
|
||||
}
|
||||
|
||||
const componentNames = (stack: string): string =>
|
||||
[...stack.matchAll(/^\s*(?:at|in)\s+([A-Za-z_$][\w$.]*)/gm)]
|
||||
.slice(0, 30)
|
||||
.map((m) => m[1])
|
||||
.join("\n");
|
||||
|
||||
const ATTRIBUTE_SELECTOR = /\[[\w:-]+(?:[~|^$*]?=[^\]]*)?\]/;
|
||||
const ID_OR_CLASS = /^\s*[#.][A-Za-z_-][\w-]*/;
|
||||
const HEX_COLOUR = /^#[0-9a-f]{3,8}$/i;
|
||||
@@ -107,6 +153,23 @@ function readsAsPathOrSelector(value: string): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
type Shaper = (key: string, value: string) => Facts | null;
|
||||
const single =
|
||||
(shape: (value: string) => string | null): Shaper =>
|
||||
(key, value) => {
|
||||
const shaped = shape(value);
|
||||
return shaped === null ? null : { [key]: shaped };
|
||||
};
|
||||
const otherValue: Shaper = (key, value) => (readsAsPathOrSelector(value) ? null : { [key]: value });
|
||||
const SHAPERS: Record<string, Shaper> = {
|
||||
...Object.fromEntries([...MESSAGE_KEYS].map((key) => [key, messageFacts])),
|
||||
...Object.fromEntries([...PATH_KEYS].map((key) => [key, pathFacts])),
|
||||
...Object.fromEntries([...SELECTOR_KEYS].map((key) => [key, selectorFacts])),
|
||||
stack_trace: single(shapedFrames),
|
||||
component_stack: single(componentNames),
|
||||
filename: single(bundleFile),
|
||||
};
|
||||
|
||||
/** A caller's properties as they may leave the machine; runs before the transport's own fields. */
|
||||
export function shapeEventProperties<V extends Value>(
|
||||
event: string,
|
||||
@@ -118,15 +181,11 @@ export function shapeEventProperties<V extends Value>(
|
||||
for (const [key, value] of Object.entries(properties)) {
|
||||
if (typeof value !== "string" || value === "" || kept?.has(key)) {
|
||||
out[key] = value;
|
||||
} else if (PATH_KEYS.has(key)) {
|
||||
Object.assign(out, pathFacts(key, value));
|
||||
} else if (SELECTOR_KEYS.has(key)) {
|
||||
Object.assign(out, selectorFacts(key, value));
|
||||
} else if (readsAsPathOrSelector(value)) {
|
||||
dropped.push(key);
|
||||
} else {
|
||||
out[key] = value;
|
||||
continue;
|
||||
}
|
||||
const facts = (SHAPERS[key] ?? otherValue)(key, value);
|
||||
if (facts) Object.assign(out, facts);
|
||||
else dropped.push(key);
|
||||
}
|
||||
if (dropped.length > 0) out.dropped_fields = dropped.join(",");
|
||||
return out;
|
||||
|
||||
@@ -140,6 +140,7 @@ export function failedCutover(
|
||||
family,
|
||||
error_kind: cutoverErrorKind(err),
|
||||
...(err instanceof StudioSaveHttpError ? { status: err.statusCode } : {}),
|
||||
error_name: err.name,
|
||||
error: err.message,
|
||||
});
|
||||
return { status: "failed", error: err };
|
||||
@@ -273,7 +274,8 @@ function refreshCommittedEdit(after: string, deps: CutoverDeps, options?: Cutove
|
||||
if (deps.refresh) deps.refresh(after);
|
||||
else if (!options?.skipRefresh) deps.reloadPreview();
|
||||
} catch (error) {
|
||||
trackStudioEvent("sdk_cutover_refresh_failed", { error: asCutoverError(error).message });
|
||||
const err = asCutoverError(error);
|
||||
trackStudioEvent("sdk_cutover_refresh_failed", { error_name: err.name, error: err.message });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,9 +308,11 @@ async function commitCandidateEdit(
|
||||
// candidate here can make all three authorities disagree (or dispose the
|
||||
// now-live session). Production publishers are non-throwing; keep the
|
||||
// durable commit authoritative and surface this post-commit fault.
|
||||
const err = asCutoverError(error);
|
||||
trackStudioEvent("sdk_cutover_publish_failed", {
|
||||
path: targetPath,
|
||||
error: asCutoverError(error).message,
|
||||
error_name: err.name,
|
||||
error: err.message,
|
||||
});
|
||||
}
|
||||
if (refreshTarget) refreshCommittedEdit(edit.after, deps, options);
|
||||
|
||||
@@ -255,20 +255,23 @@ import { recordAttempt } from "./sdkResolverAttempts";
|
||||
|
||||
// ─── Telemetry ────────────────────────────────────────────────────────────────
|
||||
|
||||
// Redact all user-content values before telemetry: style values and text both
|
||||
// carry user data. Keep only the length so we can detect truncation without
|
||||
// leaking the actual bytes.
|
||||
// User content leaves as its length only (style values, text, error words); the selector-built
|
||||
// animationId goes too, as the event's own animationId is shaped.
|
||||
function redactValue(value: string | null | undefined): string | null | undefined {
|
||||
if (value == null) return value;
|
||||
return `[redacted len=${value.length}]`;
|
||||
}
|
||||
|
||||
function redactMismatches(mismatches: SdkResolverMismatch[]): SdkResolverMismatch[] {
|
||||
return mismatches.map((m) => ({
|
||||
...m,
|
||||
expected: redactValue(m.expected),
|
||||
actual: redactValue(m.actual),
|
||||
}));
|
||||
function redactMismatches(mismatches: SdkResolverMismatch[]): string {
|
||||
return JSON.stringify(
|
||||
mismatches.map((m) => ({
|
||||
...m,
|
||||
expected: redactValue(m.expected),
|
||||
actual: redactValue(m.actual),
|
||||
error: redactValue(m.error),
|
||||
animationId: undefined,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,7 +306,7 @@ function reportEmptySession(session: Composition, opLabel: string): boolean {
|
||||
sessionEmpty: true,
|
||||
sessionElementCount: 0,
|
||||
mismatchCount: 1,
|
||||
mismatches: JSON.stringify([{ kind: "session_empty" } satisfies SdkResolverMismatch]),
|
||||
mismatches: redactMismatches([{ kind: "session_empty" } satisfies SdkResolverMismatch]),
|
||||
});
|
||||
}
|
||||
return true;
|
||||
@@ -372,7 +375,7 @@ export function runResolverShadow(
|
||||
// attribute count came back 0 — see the sourceHfIdCount comment above.
|
||||
...(strictCount === 0 ? { sourceLooseMatchOnly: true } : {}),
|
||||
mismatchCount: mismatches.length,
|
||||
mismatches: JSON.stringify(redactMismatches(mismatches)),
|
||||
mismatches: redactMismatches(mismatches),
|
||||
});
|
||||
} catch {
|
||||
// never propagate from the shadow path
|
||||
@@ -457,7 +460,7 @@ export async function recordResolverParity(
|
||||
// fail-open without the suppression/count checks" from "no reader wired".
|
||||
...(sourceReadFailed ? { sourceReadFailed: true } : {}),
|
||||
mismatchCount: 1,
|
||||
mismatches: JSON.stringify([
|
||||
mismatches: redactMismatches([
|
||||
{ kind: "element_not_found", hfId } satisfies SdkResolverMismatch,
|
||||
]),
|
||||
});
|
||||
@@ -566,7 +569,7 @@ export async function recordAnimationResolverParity(
|
||||
...(diskChecked ? { diskChecked: true } : {}),
|
||||
...(sourceReadFailed ? { sourceReadFailed: true } : {}),
|
||||
mismatchCount: 1,
|
||||
mismatches: JSON.stringify([{ kind: "animation_not_found" } satisfies SdkResolverMismatch]),
|
||||
mismatches: redactMismatches([{ kind: "animation_not_found" } satisfies SdkResolverMismatch]),
|
||||
});
|
||||
} catch {
|
||||
// never propagate from the shadow path
|
||||
|
||||
Reference in New Issue
Block a user