fix: survive empty-string env vars from compose

Docker Compose passes undeclared variables as empty strings
(CRON_SECRET="" etc.), which crashed env validation while loading the
instrumentation hook. A throwing register() made Next.js answer every
route with 500 while the process stayed alive.

- parse optional CRON_SECRET / AUTO_RULE_SYNC_INTERVAL_SECONDS via
  plain preprocess helpers that map blank strings to unset (zod v4
  does not accept preprocess-produced undefined through .optional())
- guard instrumentation register() so scheduler failures can never
  break request handling
This commit is contained in:
Leon Tonhäuser committed 2026-08-25 01:16:13 +02:00
1 parent dd60fd6ee6
commit c6b69eb88d
3 files changed
+102 -7

No files matched your search

+9 -2
View File
@@ -1,7 +1,14 @@
export async function register(): Promise<void> {
// The album auto-rule sync is best-effort: a failure here must never take
// down request handling (a throwing register() makes Next.js answer every
// route with 500).
if (process.env.NEXT_RUNTIME !== "nodejs") {
return;
}
const { startAutoRuleScheduler } = await import("@/modules/albums/auto-rule-scheduler");
startAutoRuleScheduler();
try {
const { startAutoRuleScheduler } = await import("@/modules/albums/auto-rule-scheduler");
startAutoRuleScheduler();
} catch (error) {
console.error("[auto-rule-sync] scheduler disabled after startup error:", error);
}
}