fix: address code review feedback (batch 2)

1. Add logger to writeCacheFile (version-cache.ts)
   - Now logs warnings when file write fails
   - Helps debugging in production environments

2. Sanitize logging in parseGroupResult (communities.ts)
   - Changed from info to debug level
   - Removed full node/groupNode dumps (sensitive data)
   - Now only logs nodeTag and groupId

3. Add input validation in parseNewsletterCreateResponse (newsletter.ts)
   - Validates response structure before destructuring
   - Adds fallback values for parseInt (prevents NaN)
   - Adds null checks for optional fields

4. Add health-status.ts module
   - getHealthStatus(): Full health check with circuit breakers, cache, memory
   - isHealthy(): Simple boolean for liveness probes
   - getSimpleHealthStatus(): Returns 'ok', 'degraded', or 'error'
   - Useful for k8s probes and monitoring dashboards
This commit is contained in:
Claude
2026-01-24 20:04:53 +00:00
parent 22eda03eb2
commit d132e1cfd8
5 changed files with 243 additions and 15 deletions
+9 -4
View File
@@ -86,11 +86,16 @@ async function readCacheFile(filePath: string): Promise<VersionCacheEntry | null
/**
* Writes the cache to file
*/
async function writeCacheFile(filePath: string, entry: VersionCacheEntry): Promise<void> {
async function writeCacheFile(
filePath: string,
entry: VersionCacheEntry,
logger?: VersionCacheLogger
): Promise<void> {
try {
await fs.writeFile(filePath, JSON.stringify(entry, null, 2), 'utf-8')
} catch {
// Ignore write errors - cache is optional
} catch (error) {
// Log write errors for debugging - cache is optional but failures should be visible
logger?.warn({ error, filePath }, 'Failed to write version cache file')
}
}
@@ -124,7 +129,7 @@ async function fetchVersionOnce(
memoryCache = entry
// Persist to file (async, don't wait)
writeCacheFile(cacheFilePath, entry).catch(() => {})
writeCacheFile(cacheFilePath, entry, logger).catch(() => {})
logger?.info(
{ version: entry.version, source: entry.source },