Skip to content

Write HTML. Render video. Built for agents.

fix(producer): degrade gracefully when font cache directory is unwritable (#3572)

miga-heygenda09428af190
diff --git a/packages/producer/src/services/deterministicFonts.ts b/packages/producer/src/services/deterministicFonts.ts
index 7b99aad6e1..3f537a7917 100644
--- a/packages/producer/src/services/deterministicFonts.ts
+++ b/packages/producer/src/services/deterministicFonts.ts
@@ -746,10 +746,27 @@ function fontSlug(familyName: string): string {
.replace(/^-|-$/g, "");
}
+let ephemeralFontCacheRoot: string | undefined;
+
function fontCacheDir(slug: string): string {
const dir = join(resolveFontCacheRoot(), slug);
if (!existsSync(dir)) {
- mkdirSync(dir, { recursive: true });
+ try {
+ mkdirSync(dir, { recursive: true });
+ } catch {
+ const firstFallback = ephemeralFontCacheRoot === undefined;
+ ephemeralFontCacheRoot ??= mkdtempSync(join(tmpdir(), "hyperframes-fonts-"));
+ const fallback = join(ephemeralFontCacheRoot, slug);
+ mkdirSync(fallback, { recursive: true });
+ if (firstFallback) {
+ defaultLogger.warn(
+ `Font cache directory is unwritable (${dir}). ` +
+ `Using temporary fallback — fonts will re-download each run. ` +
+ `Fix with: chmod 755 ${resolveFontCacheRoot()}`,
+ );
+ }
+ return fallback;
+ }
}
return dir;
}