mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-17 15:24:19 +00:00
26 lines
1.0 KiB
TypeScript
26 lines
1.0 KiB
TypeScript
/** A drawElement page cannot supply trusted pixels; retry on a fresh screenshot page. */
|
|
export class DrawElementCaptureError extends Error {
|
|
readonly frameIndex: number;
|
|
|
|
constructor(frameIndex: number, reason: string, cause?: unknown) {
|
|
super(
|
|
`drawElement capture failed at frame ${frameIndex}: ${reason}; fresh screenshot capture required`,
|
|
{ cause },
|
|
);
|
|
this.name = "DrawElementCaptureError";
|
|
// Consumed structurally across package/worker error boundaries.
|
|
Object.defineProperty(this, "deCaptureFailure", { value: true, enumerable: true });
|
|
this.frameIndex = frameIndex;
|
|
}
|
|
}
|
|
|
|
/** Structural matching survives engine/producer copies and worker error wrappers. */
|
|
export function isDrawElementCaptureError(error: unknown): boolean {
|
|
let current = error;
|
|
for (let depth = 0; depth < 5 && typeof current === "object" && current !== null; depth++) {
|
|
if ("deCaptureFailure" in current && current.deCaptureFailure === true) return true;
|
|
current = "cause" in current ? current.cause : undefined;
|
|
}
|
|
return false;
|
|
}
|