Open source CapCut alternative.
TypeScript
fix(site): drop cancellations and injected syntax errors
David Leb37cfeb923f4
diff --git a/site/src/instrumentation-client.test.ts b/site/src/instrumentation-client.test.tsindex cfcbdeee..0149ebf6 100644--- a/site/src/instrumentation-client.test.ts+++ b/site/src/instrumentation-client.test.ts@@ -114,6 +114,41 @@ describe("before_send", () => {expect(beforeSend(exception(report, cause))).not.toBeNull();});+ test("drops a cancellation nothing was left waiting on", () => {+ // A discarded chat round aborts its request; the abort's own reason+ // reaches the page as an unhandled rejection with the abort() call as its+ // stack, or no stack at all.+ const chrome = {+ type: "DOMException",+ value: "AbortError: signal is aborted without reason",+ stacktrace: { frames: [{ filename: "https://donkeycut.com/_next/static/chunks/a.js" }] },+ };+ const safari = { type: "DOMException", value: "AbortError: The operation was aborted." };++ expect(beforeSend(exception(chrome))).toBeNull();+ expect(beforeSend(exception(safari))).toBeNull();+ });++ test("keeps a worded report whose cause is a cancellation", () => {+ const report = { type: "Error", value: "[cut] export failed" };+ const cause = { type: "DOMException", value: "AbortError: signal is aborted without reason" };++ expect(beforeSend(exception(report, cause))).not.toBeNull();+ });++ test("drops a compile error in code no file holds", () => {+ const evaluated = { type: "SyntaxError", value: "Octal escape sequences are not allowed in template strings." };++ expect(beforeSend(exception(evaluated))).toBeNull();+ });++ test("keeps a response body that failed to parse", () => {+ // Response.json() rejects from native code, with no frame of ours.+ const ours = { type: "SyntaxError", value: "Unexpected token '<', \"<!DOCTYPE \"... is not valid JSON" };++ expect(beforeSend(exception(ours))).not.toBeNull();+ });+test("keeps an error our own code threw", () => {const ours = {type: "TypeError",diff --git a/site/src/instrumentation-client.ts b/site/src/instrumentation-client.tsindex 78a4eb5b..3a166c5a 100644--- a/site/src/instrumentation-client.ts+++ b/site/src/instrumentation-client.ts@@ -124,6 +124,25 @@ const translatorArtifact = (item: { value?: string }) => {const droppedFetch = (item: { type?: string; value?: string }) =>item?.type === "TypeError" && typeof item.value === "string" && fetchDropped(new TypeError(item.value));+/**+ * Whether this exception is a cancellation, reported bare. Cut stops work it+ * no longer wants by aborting it — a discarded chat round, a superseded read+ * — and an abort whose rejection nothing awaited reaches the page carrying+ * only the abort() call, or no stack at all. report.ts holds back the same+ * shape; a failure worded around an abort keeps it as its cause and stays.+ */+const cancellation = (item: { type?: string; value?: string }) =>+ item?.type === "DOMException" && typeof item.value === "string" && item.value.startsWith("AbortError:");++/**+ * Whether this exception is a compile error in code no file holds. A shipped+ * chunk that failed to parse names its file, so a syntax error with no frame+ * at all came from source something evaluated into the page. A body that+ * failed to parse as JSON also arrives frameless, from native code, and stays.+ */+const evaluatedSyntaxError = (item: { type?: string; value?: string; stacktrace?: { frames?: unknown[] } }) =>+ item?.type === "SyntaxError" && !item.stacktrace?.frames?.length && !/JSON/.test(item.value ?? "");+// A tab left open across a deploy recovers from the old build's missing chunks.if (process.env.NODE_ENV === "production") {reloadOnChunkError(window);@@ -161,7 +180,9 @@ if (process.env.NEXT_PUBLIC_POSTHOG_KEY && process.env.NODE_ENV === "production"opaqueScriptError(list[0]) ||browserNoise(list[0]) ||translatorArtifact(list[0]) ||- droppedFetch(list[0])+ droppedFetch(list[0]) ||+ cancellation(list[0]) ||+ evaluatedSyntaxError(list[0])) {return null;}