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:
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user