Skip to content

Commit c01e1a5

Browse files
committed
fix(producer): narrow extraction error shapes honestly
1 parent 9b63646 commit c01e1a5

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

‎packages/engine/src/services/videoFrameExtractor.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ export function isVideoSourceExtractionError(error: unknown): error is VideoSour
198198
return (
199199
typeof error === "object" &&
200200
error !== null &&
201-
(error as { hyperframesVideoSourceExtractionError?: unknown })
202-
.hyperframesVideoSourceExtractionError === true
201+
"hyperframesVideoSourceExtractionError" in error &&
202+
error.hyperframesVideoSourceExtractionError === true
203203
);
204204
}
205205

‎packages/producer/src/server.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,19 @@ interface PreparedRenderInput {
118118
}
119119

120120
const DEFAULT_SERVER_FPS = { num: 30, den: 1 } as const;
121-
const SAFE_RENDER_ERROR_CODES = new Set([
121+
const SAFE_RENDER_ERROR_CODES = new Set<string>([
122122
"VIDEO_SOURCE_UNRENDERABLE",
123123
"VIDEO_EXTRACTION_FAILED",
124-
] as const);
124+
]);
125125

126126
/**
127127
* Preserve only bounded producer error codes across JSON/SSE. Never derive a
128128
* code from the message: it may contain local paths or signed source URLs.
129129
*/
130130
export function extractSafeRenderErrorCode(error: unknown): string | undefined {
131131
if (typeof error !== "object" || error === null || !("code" in error)) return undefined;
132-
const code = (error as { code?: unknown }).code;
133-
return typeof code === "string" &&
134-
SAFE_RENDER_ERROR_CODES.has(code as "VIDEO_SOURCE_UNRENDERABLE" | "VIDEO_EXTRACTION_FAILED")
135-
? code
136-
: undefined;
132+
const code = error.code;
133+
return typeof code === "string" && SAFE_RENDER_ERROR_CODES.has(code) ? code : undefined;
137134
}
138135

139136
function parseServerFps(value: unknown): RenderInput["fps"] {

‎packages/producer/src/services/render/stages/extractVideosStage.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,11 @@ describe("assertVideoExtractionSucceeded", () => {
193193
{ kind: "zero_output", count: 1 },
194194
],
195195
});
196-
expect((caught as Error).message).not.toContain("/tmp/");
197-
expect((caught as Error).message).not.toContain("Signature");
196+
if (!(caught instanceof Error)) {
197+
throw new Error("expected VideoExtractionStageError");
198+
}
199+
expect(caught.message).not.toContain("/tmp/");
200+
expect(caught.message).not.toContain("Signature");
198201
});
199202

200203
it("keeps exhausted transient failures retryable and collapses duplicate kinds", () => {

0 commit comments

Comments
 (0)