Skip to content

Commit 7425042

Browse files
Miriadpm
andcommitted
fix: getConfigValue falls back when field is undefined/null
When a Sanity singleton exists but a field hasn't been set yet, config[key] returns undefined. Previously the fallback only applied when getConfig() threw (doc missing entirely). Now fallback is used whenever the value is undefined or null. Fixes RangeError: Invalid time value in ingest cron when dedupWindowDays is unset in Sanity. Co-authored-by: pm <pm@miriad.systems>
1 parent 9dc65ca commit 7425042

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ export async function getConfigValue<
9494
): Promise<ConfigTypeMap[T][K]> {
9595
try {
9696
const config = await getConfig(table);
97-
return config[key];
97+
const value = config[key];
98+
// Use fallback when field is undefined/null (not yet set in Sanity)
99+
if (value === undefined || value === null) {
100+
if (fallback !== undefined) return fallback;
101+
}
102+
return value;
98103
} catch {
99104
if (fallback !== undefined) return fallback;
100105
throw new Error(`Config value ${String(key)} not found in ${table}`);

0 commit comments

Comments
 (0)