Open source CapCut alternative.
TypeScript
fix(site): keep a recovered media read out of error tracking
David Le0d54dea341b8
diff --git a/site/src/cut/lib/report.ts b/site/src/cut/lib/report.tsindex d8a0a0a8..fd799457 100644--- a/site/src/cut/lib/report.ts+++ b/site/src/cut/lib/report.ts@@ -34,6 +34,13 @@* browser words it differently.*/function transient(err: unknown): boolean {+ // A read layer that names its own failures (mediaRead.ts wraps a refused+ // network read) carries the original underneath, and that is the shape which+ // decides.+ return shape(err) || (err instanceof Error && err.cause != null && shape(err.cause));+}++function shape(err: unknown): boolean {if (err instanceof DOMException) {return (// The read was torn down: a scrub superseded it, a clip closed, the tabdiff --git a/site/src/instrumentation-client.ts b/site/src/instrumentation-client.tsindex cd7a4cb3..934911ad 100644--- a/site/src/instrumentation-client.ts+++ b/site/src/instrumentation-client.ts@@ -28,6 +28,19 @@ const fromInjectedScript = (item: { stacktrace?: { frames?: { filename?: stringreturn Array.isArray(frames) && frames.length > 0 && frames.every((f) => !f?.filename);};+/**+ * Whether this exception is a media read that never reached the file.+ *+ * A media source reads ahead of what anyone asked for, and mediabunny rethrows+ * a failed readahead so it isn't swallowed — with nothing awaiting those bytes+ * it reaches the page as an unhandled rejection with no failure behind it: the+ * next read of that range fetches it again, and reads someone is waiting on+ * reject into callers that retry. The read layer (cut/lib/mediaRead.ts) names+ * these, including the ones it refuses outright because the Donkey app is+ * closed, which the connect gate is already saying on screen.+ */+const recoveredMediaRead = (item: { type?: string }) => item?.type === "MediaFetchError";+// Production builds only: a dev server on localhost sends HMR build overlays// and half-saved-file errors straight into production error tracking.if (process.env.NEXT_PUBLIC_POSTHOG_KEY && process.env.NODE_ENV === "production") {@@ -50,7 +63,9 @@ if (process.env.NEXT_PUBLIC_POSTHOG_KEY && process.env.NODE_ENV === "production"if (event?.event === "$exception") {const list = event.properties?.$exception_list;if (Array.isArray(list)) {- if (list.some(fromInjectedScript)) return null;+ // Only as the exception itself: a report worded around one (its+ // cause, further down the list) is a failure that outlived retries.+ if (list.some(fromInjectedScript) || recoveredMediaRead(list[0])) return null;for (const item of list) {if (typeof item?.value === "string") item.value = scrubUrls(item.value);}