{"record":{"id":"148d423a605afd68","repo":"gastownhall/beads","slug":"backup-destination-does-not-exist-w-148d42","errorCode":null,"errorMessage":"backup destination does not exist: %w","messagePattern":"backup destination does not exist: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/embeddeddolt/version_control.go","lineNumber":734,"sourceCode":"func (s *EmbeddedDoltStore) BackupSync(ctx context.Context, name string) error {\n\treturn s.withMutatingDBConn(ctx, func(db versioncontrolops.DBConn) error {\n\t\treturn versioncontrolops.BackupSync(ctx, db, name)\n\t})\n}\n\nfunc (s *EmbeddedDoltStore) BackupRemove(ctx context.Context, name string) error {\n\treturn s.withMutatingDBConn(ctx, func(db versioncontrolops.DBConn) error {\n\t\treturn versioncontrolops.BackupRemove(ctx, db, name)\n\t})\n}\n\n// BackupDatabase registers dir as a file:// Dolt backup remote and syncs\n// the database to it. The dir must exist locally. This preserves full Dolt\n// commit history.\nfunc (s *EmbeddedDoltStore) BackupDatabase(ctx context.Context, dir string) error {\n\tinfo, err := os.Stat(dir)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"backup destination does not exist: %w\", err)\n\t}\n\tif !info.IsDir() {\n\t\treturn fmt.Errorf(\"backup destination is not a directory: %s\", dir)\n\t}\n\n\tbackupURL, err := versioncontrolops.DirToFileURL(dir)\n\tif err != nil {\n\t\treturn err\n\t}\n\tbackupName := \"backup_export\"\n\n\treturn s.withMutatingDBConn(ctx, func(db versioncontrolops.DBConn) error {\n\t\t// Register as a backup remote (idempotent — remove first if exists).\n\t\t_ = versioncontrolops.BackupRemove(ctx, db, backupName)\n\t\tif err := versioncontrolops.BackupAdd(ctx, db, backupName, backupURL); err != nil {\n\t\t\t// Another backup (e.g. \"default\" registered by `bd backup init`) may\n\t\t\t// already point to this URL. In that case, sync using the existing\n\t\t\t// remote name rather than failing.","sourceCodeStart":716,"sourceCodeEnd":752,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/embeddeddolt/version_control.go#L716-L752","documentation":"Returned by EmbeddedDoltStore.BackupDatabase when the destination directory passed to it cannot be stat-ed, meaning it does not exist (or is otherwise inaccessible). Dolt file:// backups require an existing local directory, so the store fails fast with the underlying os.Stat error wrapped.","triggerScenarios":"Calling BackupDatabase(ctx, dir) with a dir that does not exist, has a typo'd path, or is unreadable due to permissions — os.Stat returns an error which is wrapped verbatim.","commonSituations":"Typo in backup path; relative path resolved from the wrong working directory; backup volume not mounted in a container; permission denied on the target directory.","solutions":["Create the directory first: mkdir -p <dir> (BackupDatabase requires it to pre-exist)","Fix typos and use absolute paths for the backup destination","Check mount status and permissions on the target path","Ensure the bd process user can read/write the directory"],"exampleFix":"// before\nerr := store.BackupDatabase(ctx, \"/backups/beads\")\n// after\nif err := os.MkdirAll(\"/backups/beads\", 0o755); err != nil { return err }\nerr = store.BackupDatabase(ctx, \"/backups/beads\")","handlingStrategy":"validation","validationCode":"func ensureBackupDir(dir string) error {\n    info, err := os.Stat(dir)\n    if err != nil {\n        if os.IsNotExist(err) { return os.MkdirAll(dir, 0o755) }\n        return err\n    }\n    if !info.IsDir() { return fmt.Errorf(\"%%s is not a directory\", dir) }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := store.BackupDatabase(ctx, dir); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && os.IsNotExist(pe) { /* create dir and retry */ }\n}","preventionTips":["Always mkdir -p the backup destination before calling","Use absolute paths for backup targets","Check volume mounts in containerized environments"],"tags":["go","dolt","backup","filesystem"],"backgroundTag":"path-not-found","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}