mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* fix(engine): a failed drawElement worker encode takes the fresh-session recovery The encode result is awaited after its frame was produced. Its failure reached the stage as a plain error, so the render ended. It now surfaces as a drawElement capture failure, like a failed produce. * fix(engine): drop the comments from the encode failure wrapper
43 lines
1.6 KiB
TypeScript
43 lines
1.6 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;
|
|
}
|
|
}
|
|
|
|
function markRejectionHandled(promise: Promise<unknown>): void {
|
|
promise.catch(() => {});
|
|
}
|
|
|
|
export function asDrawElementCaptureFailure(
|
|
frameIndex: number,
|
|
encodeResult: Promise<Buffer>,
|
|
): Promise<Buffer> {
|
|
const wrapped = encodeResult.catch((cause: unknown) => {
|
|
if (isDrawElementCaptureError(cause)) throw cause;
|
|
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
throw new DrawElementCaptureError(frameIndex, reason, cause);
|
|
});
|
|
markRejectionHandled(wrapped);
|
|
return wrapped;
|
|
}
|
|
|
|
/** 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;
|
|
}
|