From feb20a59705904bef4f5d53b1fda066e17fa4593 Mon Sep 17 00:00:00 2001 From: Toha Date: Tue, 7 Jul 2026 07:41:49 +0700 Subject: [PATCH] Prevent circular structure error when logging site configuration. Signed-off-by: Toha --- scripts/commands/epg/grab.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/commands/epg/grab.ts b/scripts/commands/epg/grab.ts index 122993ffc..ee135f4a5 100644 --- a/scripts/commands/epg/grab.ts +++ b/scripts/commands/epg/grab.ts @@ -134,7 +134,7 @@ async function main() { globalConfig.json = options.json if (typeof options.debug === 'boolean') globalConfig.debug = options.debug - logger.debug(`config: ${JSON.stringify(globalConfig, null, 2)}`) + logger.debug(`config: ${JSON.stringify(globalConfig, getCircularReplacer(), 2)}`) const grabber = process.env.NODE_ENV === 'test' @@ -143,7 +143,7 @@ async function main() { grabber.client.instance.interceptors.request.use( request => { - logger.debug(`request: ${JSON.stringify(request, null, 2)}`) + logger.debug(`request: ${JSON.stringify(request, getCircularReplacer(), 2)}`) const curl = globalConfig.curl || defaultConfig.curl if (curl) { @@ -357,3 +357,16 @@ function getLogoForChannel(channel: Channel): string | null { return null } + +function getCircularReplacer() { + const seen = new WeakSet() + return (key: string, value: any) => { + if (typeof value === 'object' && value !== null) { + if (seen.has(value)) { + return '[Circular]' + } + seen.add(value) + } + return value + } +}