From 80459e83365fc79174ed63293da21def88ae57e2 Mon Sep 17 00:00:00 2001 From: "khalid@traclabs.com" Date: Thu, 23 Apr 2026 00:05:17 -0500 Subject: [PATCH] Add logging --- server/src/queue/manifest.ts | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/server/src/queue/manifest.ts b/server/src/queue/manifest.ts index 8182d81..8570640 100644 --- a/server/src/queue/manifest.ts +++ b/server/src/queue/manifest.ts @@ -1,6 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { sectionFileSchema } from '@dynamic-sites/shared'; +import { logger } from '../logger.js'; const REPO_ROOT = process.env.REPO_ROOT || '.'; @@ -18,13 +19,25 @@ export function buildSectionManifest(): ManifestEntry[] { const sectionsDir = path.join(REPO_ROOT, 'content/sections'); const manifest: ManifestEntry[] = []; - if (!fs.existsSync(sectionsDir)) return manifest; + if (!fs.existsSync(sectionsDir)) { + logger.warn({ event: 'manifest.dir_missing', path: sectionsDir }, 'Sections directory does not exist'); + return manifest; + } - for (const file of fs.readdirSync(sectionsDir).filter(f => f.endsWith('.json'))) { + const files = fs.readdirSync(sectionsDir).filter(f => f.endsWith('.json')); + logger.info({ event: 'manifest.scan', path: sectionsDir, fileCount: files.length, files }, 'Scanning sections directory'); + + for (const file of files) { + const filePath = path.join(sectionsDir, file); try { - const raw = JSON.parse(fs.readFileSync(path.join(sectionsDir, file), 'utf-8')); + const rawText = fs.readFileSync(filePath, 'utf-8'); + const raw = JSON.parse(rawText); const parsed = sectionFileSchema.safeParse(raw); - if (!parsed.success) continue; + + if (!parsed.success) { + logger.warn({ event: 'manifest.parse_failed', file, errors: parsed.error.issues.map(i => `${i.path.join('.')}: ${i.message}`) }, 'Section file failed schema validation'); + continue; + } const s = parsed.data; const entry: ManifestEntry = { @@ -39,7 +52,9 @@ export function buildSectionManifest(): ManifestEntry[] { if (s.type === 'text') entry.heading = s.heading; manifest.push(entry); - } catch { /* skip bad files */ } + } catch (err) { + logger.error({ event: 'manifest.read_error', file, error: (err as Error).message }, 'Failed to read section file'); + } } // Also add events.json @@ -51,5 +66,7 @@ export function buildSectionManifest(): ManifestEntry[] { visible: true, }); + logger.info({ event: 'manifest.built', sectionCount: manifest.length }, 'Manifest built'); + return manifest; }