{"record":{"id":"85ca0339b4b5f0e5","repo":"eyaltoledano/claude-task-master","slug":"failed-to-create-backup-error-message","errorCode":null,"errorMessage":"Failed to create backup: ${error.message}","messagePattern":"Failed to create backup: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/workflow/managers/workflow-state-manager.ts","lineNumber":185,"sourceCode":"\t\t\tawait fs.mkdir(this.backupDir, { recursive: true });\n\n\t\t\tconst timestamp = new Date().toISOString().replace(/[:.]/g, '-');\n\t\t\tconst backupPath = path.join(\n\t\t\t\tthis.backupDir,\n\t\t\t\t`workflow-state-${timestamp}.json`\n\t\t\t);\n\n\t\t\tconst backup: WorkflowStateBackup = {\n\t\t\t\ttimestamp: new Date().toISOString(),\n\t\t\t\tstate\n\t\t\t};\n\n\t\t\tawait fs.writeFile(backupPath, JSON.stringify(backup, null, 2), 'utf-8');\n\n\t\t\t// Clean up old backups\n\t\t\tawait this.pruneBackups();\n\t\t} catch (error: any) {\n\t\t\tthrow new Error(`Failed to create backup: ${error.message}`);\n\t\t}\n\t}\n\n\t/**\n\t * Delete workflow state file\n\t */\n\tasync delete(): Promise<void> {\n\t\ttry {\n\t\t\tawait fs.unlink(this.statePath);\n\t\t} catch (error: any) {\n\t\t\tif (error.code !== 'ENOENT') {\n\t\t\t\tthrow new Error(`Failed to delete workflow state: ${error.message}`);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * List available backups","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/workflow/managers/workflow-state-manager.ts#L167-L203","documentation":"createBackup() writes a JSON snapshot of the current state to the backup directory and then prunes old backups. Any failure — reading current state, creating/writing the backup file, or pruning — is wrapped as 'Failed to create backup: <cause>'.","triggerScenarios":"Calling createBackup() when the backup directory does not exist and cannot be created, is not writable, the current state file is missing/unreadable, or pruneBackups() throws (e.g. permission errors on old backup files).","commonSituations":"Backup dir on a full disk; mismatched permissions after running as different user; state file deleted between read and write; ENOENT on the state file when backing up before a risky operation.","solutions":["Read the cause after the colon to identify the failing step (mkdir, writeFile, or pruneBackups).","Ensure both the state directory and backupDir exist and are writable by the process.","Check disk space if the cause is ENOSPC.","Verify the current state file exists before calling createBackup, or create state first.","Fix permissions on old backup files if pruning fails."],"exampleFix":"// before\nawait manager.createBackup(); // fails if backup dir missing\n// after\nawait fs.mkdir(backupDir, { recursive: true });\nawait manager.createBackup();","handlingStrategy":"validation","validationCode":"import { stat, mkdir } from 'fs/promises';\nawait mkdir(backupDir, { recursive: true });\nawait stat(backupDir); // ensure accessible\ntry { await access(constants.W_OK, backupDir); } catch { throw new Error('backup dir not writable'); }","typeGuard":"null","tryCatchPattern":"try {\n  await manager.createBackup();\n} catch (e) {\n  if (e.message.includes('ENOENT')) await fs.mkdir(backupDir, { recursive: true });\n  throw e;\n}","preventionTips":["Create the backup directory during setup/bootstrap","Check disk space before large backups","Keep backup file permissions consistent across users","Verify state file exists before backing up"],"tags":["filesystem","backup","workflow"],"backgroundTag":"backup-write-failed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}