Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: classify no-speech errors across workflow realms

Richie McIlroy94e883891fd2
diff --git a/apps/web/__tests__/integration/transcribe-workflow.test.ts b/apps/web/__tests__/integration/transcribe-workflow.test.ts
index bab63f58d..3ca5d49b9 100644
--- a/apps/web/__tests__/integration/transcribe-workflow.test.ts
+++ b/apps/web/__tests__/integration/transcribe-workflow.test.ts
@@ -98,9 +98,12 @@ vi.mock("drizzle-orm", () => ({
vi.mock("server-only", () => ({}));
-vi.mock("workflow", () => ({
- FatalError: class FatalError extends Error {},
-}));
+vi.mock("workflow", async () => {
+ const { runInNewContext } = await import("node:vm");
+ return {
+ FatalError: runInNewContext("(class FatalError extends Error {})"),
+ };
+});
vi.mock("workflow/api", () => ({
start: vi.fn(),
@@ -245,7 +248,9 @@ describe("transcribeVideoWorkflow", () => {
expect(mocks.updates.at(-1)).toEqual({ transcriptionStatus: "COMPLETE" });
});
- it("marks audio without speech as skipped without retrying transcription", async () => {
+ it("handles no-speech errors across workflow realms without retrying transcription", async () => {
+ const { FatalError } = await import("workflow");
+ expect(new FatalError("no spoken audio")).not.toBeInstanceOf(Error);
mocks.transcribe.mockResolvedValueOnce({
id: "silent-transcript",
status: "error",
@@ -268,6 +273,7 @@ describe("transcribeVideoWorkflow", () => {
expect(mocks.updates).toContainEqual({ transcriptionStatus: "NO_AUDIO" });
expect(mocks.updates).not.toContainEqual({ transcriptionStatus: "ERROR" });
expect(mocks.startAiGeneration).not.toHaveBeenCalled();
+ expect(mocks.deleteObject).toHaveBeenCalledTimes(1);
});
it("preserves transcription failures unrelated to missing speech", async () => {
diff --git a/apps/web/workflows/transcribe.ts b/apps/web/workflows/transcribe.ts
index c0daefec3..a281d25f1 100644
--- a/apps/web/workflows/transcribe.ts
+++ b/apps/web/workflows/transcribe.ts
@@ -162,7 +162,10 @@ export async function transcribeVideoWorkflow(
await saveTranscription(videoId, userId, videoData.video, transcription);
} catch (error) {
if (
- error instanceof Error &&
+ typeof error === "object" &&
+ error !== null &&
+ "message" in error &&
+ typeof error.message === "string" &&
error.message.toLowerCase().includes("no spoken audio")
) {
await markNoAudio(videoId);