Skip to content

Commit b12ecc5

Browse files
authored
fix(media-use): keep the network cause in Gemini TTS errors
1 parent 64c7bbf commit b12ecc5

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎skills-manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"files": 13
1919
},
2020
"media-use": {
21-
"hash": "523f018498ca8fdd",
21+
"hash": "2fc06949c008a514",
2222
"files": 116
2323
},
2424
"remotion-to-hyperframes": {

‎skills/media-use/audio/scripts/lib/gemini-tts.mjs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export async function synthesizeGemini(
8686
return { ok: true, words: null };
8787
} catch (error) {
8888
// Error responses must never echo the credential into logs or metadata.
89-
const message = String(error?.message ?? error);
89+
const message = withCause(error);
9090
return {
9191
ok: false,
9292
words: null,
@@ -95,6 +95,18 @@ export async function synthesizeGemini(
9595
}
9696
}
9797

98+
// undici reports "fetch failed" and keeps the real reason (e.g. UND_ERR_SOCKET,
99+
// "other side closed") in `error.cause`.
100+
function withCause(error) {
101+
const message = String(error?.message ?? error);
102+
const cause = error?.cause;
103+
if (!cause) return message;
104+
const detail = [cause.code, cause.message ?? (typeof cause === "string" ? cause : "")]
105+
.filter(Boolean)
106+
.join(": ");
107+
return detail ? `${message} (${detail})` : message;
108+
}
109+
98110
function pcmToWav(pcm, mime) {
99111
const rate = Number(/(?:^|;)\s*rate=(\d+)(?:;|$)/i.exec(mime)?.[1]);
100112
const channels = /(?:^|;)\s*channels=([^;]+)/i.exec(mime)?.[1];

‎skills/media-use/audio/scripts/lib/gemini-tts.test.mjs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ test("HTTP and network failures stay actionable without leaking the key", async
123123
},
124124
});
125125
assert.match(timeout.error, /timed out/);
126+
const socket = await synthesizeGemini(args, {
127+
fetchImpl: async () => {
128+
const cause = Object.assign(new Error("other side closed test-gemini-key"), {
129+
code: "UND_ERR_SOCKET",
130+
});
131+
throw new TypeError("fetch failed", { cause });
132+
},
133+
});
134+
assert.match(socket.error, /fetch failed \(UND_ERR_SOCKET: other side closed/);
135+
assert.ok(!socket.error.includes("test-gemini-key"));
126136
assert.equal(existsSync(args.wavAbs), false);
127137
});
128138

0 commit comments

Comments
 (0)