{"record":{"id":"21a949b1bfd142d3","repo":"gastownhall/beads","slug":"backup-directory-not-found-s-run-bd-backup-fir","errorCode":null,"errorMessage":"backup directory not found: %s\nRun 'bd backup' first to create a backup","messagePattern":"backup directory not found: (.+?)\nRun 'bd backup' first to create a backup","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/backup_restore.go","lineNumber":163,"sourceCode":"\t\treturn fmt.Errorf(\"%s; %s\", activeWorkspaceNotFoundError(), diagHint())\n\t}\n\n\tcfg, err := configfile.Load(beadsDir)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif cfg.ProjectID == dbID {\n\t\treturn nil // already in sync\n\t}\n\n\tcfg.ProjectID = dbID\n\treturn cfg.Save(beadsDir)\n}\n\nfunc validateBackupRestoreDir(dir string) error {\n\tif _, err := os.Stat(dir); os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"backup directory not found: %s\\nRun 'bd backup' first to create a backup\", dir)\n\t}\n\treturn nil\n}\n","sourceCodeStart":145,"sourceCodeEnd":167,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/backup_restore.go#L145-L167","documentation":"validateBackupRestoreDir checks that the given restore source directory exists via os.Stat before performing the restore. If the path does not exist, this friendly error is returned, reminding the user that a backup must be created first. It prevents restoring from a typo'd or never-created path.","triggerScenarios":"'bd backup restore <dir>' (or the resolved default dir) points to a path that does not exist on disk — os.Stat returns an IsNotExist error.","commonSituations":"Typo in the backup path; backup was deleted or moved; running restore on a new machine where the backup directory was never created; relative path resolved from the wrong cwd.","solutions":["Verify the path exists (ls the directory) and correct any typo","Create a backup first with 'bd backup' (or 'bd backup sync')","If the backup lives elsewhere, pass its absolute path to restore","Check for cwd/relative-path surprises — prefer absolute paths in scripts"],"exampleFix":"// before\nbd backup restore ./bacup\n// after\nbd backup   # create a backup\nbd backup restore ~/.beads/backups/myproject","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(dir); os.IsNotExist(err) || !info.IsDir() {\n\treturn fmt.Errorf(\"backup directory %q does not exist; run 'bd backup' first\", dir)\n}","typeGuard":"func dirExists(p string) bool { info, err := os.Stat(p); return err == nil && info.IsDir() }","tryCatchPattern":"if err := validateBackupRestoreDir(dir); err != nil {\n\t// prompt user or auto-create backup:\n\t// exec.Command(\"bd\", \"backup\").Run()\n\treturn err\n}","preventionTips":["Use absolute paths for backup directories in scripts and CI","Verify the backup path exists before invoking restore","Keep backups on persistent storage that survives redeploys","Create a backup as a pre-step in restore automation"],"tags":["backup","restore","path","go"],"backgroundTag":"backup-directory-not-found","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}