{"record":{"id":"602028d400fcaee8","repo":"gastownhall/beads","slug":"failed-to-create-backup-directory-w","errorCode":null,"errorMessage":"failed to create backup directory: %w","messagePattern":"failed to create backup directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/backup_export.go","lineNumber":51,"sourceCode":"\t\t\tgitRepo = filepath.Join(home, gitRepo[2:])\n\t\t}\n\t\tif _, err := os.Stat(filepath.Join(gitRepo, \".git\")); err != nil {\n\t\t\tfmt.Fprintf(os.Stderr, \"Warning: backup.git-repo %s is not a git repo, falling back to .beads/backup\\n\", gitRepo)\n\t\t} else {\n\t\t\tdir := filepath.Join(gitRepo, \"backup\")\n\t\t\tif err := os.MkdirAll(dir, 0700); err != nil {\n\t\t\t\treturn \"\", fmt.Errorf(\"failed to create backup dir in git-repo: %w\", err)\n\t\t\t}\n\t\t\treturn dir, nil\n\t\t}\n\t}\n\tbeadsDir := beads.FindBeadsDir()\n\tif beadsDir == \"\" {\n\t\treturn \"\", fmt.Errorf(\"%s; %s\", activeWorkspaceNotFoundError(), diagHint())\n\t}\n\tdir := filepath.Join(beadsDir, \"backup\")\n\tif err := os.MkdirAll(dir, 0700); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to create backup directory: %w\", err)\n\t}\n\treturn dir, nil\n}\n\n// loadBackupState reads the backup state file, returning a zero state if missing.\nfunc loadBackupState(dir string) (*backupState, error) {\n\tpath := filepath.Join(dir, \"backup_state.json\")\n\tdata, err := os.ReadFile(path) //nolint:gosec // path is constructed internally\n\tif os.IsNotExist(err) {\n\t\treturn &backupState{}, nil\n\t}\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read backup state: %w\", err)\n\t}\n\tvar state backupState\n\tif err := json.Unmarshal(data, &state); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse backup state: %w\", err)\n\t}","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/backup_export.go#L33-L69","documentation":"After resolving the workspace, backupDir creates <beadsDir>/backup with 0700 permissions; if os.MkdirAll fails it wraps the OS error as 'failed to create backup directory: %w'. The underlying cause (permission denied, read-only filesystem, file blocking the path) is preserved for diagnosis.","triggerScenarios":"Running backup export / auto-backup inside a valid workspace whose .beads directory cannot host a 'backup' subdir: read-only .beads, ownership mismatch (e.g. created by another user/sudo), or a stale file named 'backup' inside .beads.","commonSituations":"Workspace cloned by root but operated by a normal user, .beads on a read-only mount or synced/locked by another tool, disk-full conditions, or antivirus/backup software holding locks on Windows mounts.","solutions":["Fix ownership/permissions: chown/chmod the .beads directory so the running user can write (mkdir 0700 needs write+execute on .beads)","Remove/rename any non-directory file at .beads/backup blocking creation","Check the wrapped OS error for read-only or no-space conditions and free/repair accordingly","Temporarily configure backup.git-repo to a writable alternate location"],"exampleFix":"// before\nbd backup export\n// error: failed to create backup directory: mkdir .beads/backup: permission denied\n// after\nsudo chown -R \"$USER\" .beads && bd backup export","handlingStrategy":"validation","validationCode":"beadsDir := beads.FindBeadsDir()\nif info, err := os.Stat(beadsDir); err != nil || !info.IsDir() || !writable(beadsDir) {\n    return fmt.Errorf(\".beads dir missing or not writable: %s\", beadsDir)\n}","typeGuard":null,"tryCatchPattern":"dir, err := backupDir()\nif err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, fs.ErrPermission) {\n        return fmt.Errorf(\"fix .beads permissions (chown/chmod) then retry: %w\", err)\n    }\n    return err\n}","preventionTips":["Do not create .beads as root if a normal user will run bd","Ensure .beads lives on a writable volume; avoid read-only mounts","Check for files named 'backup' colliding with the directory inside .beads","Keep free disk space on the workspace volume"],"tags":["go","filesystem","permissions","backup"],"backgroundTag":"mkdir-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}