{"record":{"id":"c02bb45fdb71b020","repo":"thedotmack/claude-mem","slug":"failed-to-regenerate-folder","errorCode":null,"errorMessage":"Failed to regenerate folder","messagePattern":"Failed to regenerate folder","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/cli/claude-md-commands.ts","lineNumber":314,"sourceCode":"  }\n\n  const observations = findObservationsByFolder(db, relativeFolder, project, observationLimit);\n\n  if (observations.length === 0) {\n    return { success: false, observationCount: 0, error: 'No observations for folder' };\n  }\n\n  if (dryRun) {\n    return { success: true, observationCount: observations.length };\n  }\n\n  try {\n    const formatted = formatObservationsForClaudeMd(observations, relativeFolder);\n    writeClaudeMdToFolder(absoluteFolder, formatted);\n    return { success: true, observationCount: observations.length };\n  } catch (error) {\n    const errorMessage = error instanceof Error ? error.message : String(error);\n    logger.warn('CLAUDE_MD', 'Failed to regenerate folder', { folder: relativeFolder, error: errorMessage });\n    return { success: false, observationCount: 0, error: errorMessage };\n  }\n}\n\nfunction processAllFoldersForGeneration(\n  trackedFolders: Set<string>,\n  workingDir: string,\n  project: string,\n  dryRun: boolean,\n  observationLimit: number\n): number {\n  const db = new Database(DB_PATH, { readonly: true, create: false });\n\n  let successCount = 0;\n  let skipCount = 0;\n  let errorCount = 0;\n\n  const foldersArray = Array.from(trackedFolders).sort();","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/cli/claude-md-commands.ts#L296-L332","documentation":"regenerateFolder formats observations for a folder's CLAUDE.md and writes the file inside a try/catch. Any exception — from formatting or from writeClaudeMdToFolder (fs writes, mkdir, permission checks) — is caught, logged as this warning, and converted into a { success: false, error } result rather than thrown.","triggerScenarios":"Calling regenerateFolder when the target folder cannot be written: parent directory missing and mkdir fails, read-only filesystem, permission denied on the existing CLAUDE.md, or formatObservationsForClaudeMd throwing on malformed observation data.","commonSituations":"Running under a user without write access to project subfolders; folder deleted between scan and write; read-only CI checkout; disk-full; ENAMETOOLONG on deeply nested paths.","solutions":["Check that the folder exists and is writable by the process user (ls -ld, touch test)","Recreate the missing folder or fix permissions (chmod/chown)","Re-run the generation command after fixing the environment — the function already returns a structured error result","Inspect result.error for the underlying fs message (EACCES/ENOENT/ENOSPC) and address that specific cause"],"exampleFix":"// before\nmkdirSync(folder); // throws if parent missing\n// after\nmkdirSync(folder, { recursive: true });","handlingStrategy":"try-catch","validationCode":"if (!existsSync(absoluteFolder)) mkdirSync(absoluteFolder, { recursive: true });\naccessSync(absoluteFolder, fsConstants.W_OK);","typeGuard":"function isWritableDir(p: string): boolean { try { accessSync(p, fsConstants.W_OK); return statSync(p).isDirectory(); } catch { return false; } }","tryCatchPattern":"try {\n  writeClaudeMdToFolder(folder, formatted);\n} catch (e) {\n  return { success: false, observationCount: 0, error: e instanceof Error ? e.message : String(e) };\n}","preventionTips":["Ensure directories exist (recursive mkdir) before writing","Run generation as a user with write access to the repo","Check disk space before batch regeneration","Retry per-folder failures after fixing the fs issue — results are structured and idempotent"],"tags":["filesystem","write","claude-md"],"backgroundTag":"file-write-failed","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}