eyaltoledano/claude-task-master · error

Failed to create backup: ${error.message}

Error message

Failed to create backup: ${error.message}

What it means

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>'.

Source

Thrown at packages/tm-core/src/modules/workflow/managers/workflow-state-manager.ts:185

			await fs.mkdir(this.backupDir, { recursive: true });

			const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
			const backupPath = path.join(
				this.backupDir,
				`workflow-state-${timestamp}.json`
			);

			const backup: WorkflowStateBackup = {
				timestamp: new Date().toISOString(),
				state
			};

			await fs.writeFile(backupPath, JSON.stringify(backup, null, 2), 'utf-8');

			// Clean up old backups
			await this.pruneBackups();
		} catch (error: any) {
			throw new Error(`Failed to create backup: ${error.message}`);
		}
	}

	/**
	 * Delete workflow state file
	 */
	async delete(): Promise<void> {
		try {
			await fs.unlink(this.statePath);
		} catch (error: any) {
			if (error.code !== 'ENOENT') {
				throw new Error(`Failed to delete workflow state: ${error.message}`);
			}
		}
	}

	/**
	 * List available backups

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Read the cause after the colon to identify the failing step (mkdir, writeFile, or pruneBackups).
  2. Ensure both the state directory and backupDir exist and are writable by the process.
  3. Check disk space if the cause is ENOSPC.
  4. Verify the current state file exists before calling createBackup, or create state first.
  5. Fix permissions on old backup files if pruning fails.

Example fix

// before
await manager.createBackup(); // fails if backup dir missing
// after
await fs.mkdir(backupDir, { recursive: true });
await manager.createBackup();
Defensive patterns

Strategy: validation

Validate before calling

import { stat, mkdir } from 'fs/promises';
await mkdir(backupDir, { recursive: true });
await stat(backupDir); // ensure accessible
try { await access(constants.W_OK, backupDir); } catch { throw new Error('backup dir not writable'); }

Type guard

null

Try / catch

try {
  await manager.createBackup();
} catch (e) {
  if (e.message.includes('ENOENT')) await fs.mkdir(backupDir, { recursive: true });
  throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/85ca0339b4b5f0e5. Report an issue: GitHub.