{"record":{"id":"fba70e27eb108e3d","repo":"gastownhall/beads","slug":"s-s","errorCode":null,"errorMessage":"%s; %s","messagePattern":"%s; %s","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/backup_export.go","lineNumber":47,"sourceCode":"\tgitRepo := config.GetString(\"backup.git-repo\")\n\tif gitRepo != \"\" {\n\t\tif strings.HasPrefix(gitRepo, \"~/\") {\n\t\t\thome, _ := os.UserHomeDir()\n\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}","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/backup_export.go#L29-L65","documentation":"backupDir's fallback path uses the beads workspace directory (.beads/backup). When beads.FindBeadsDir() returns empty, it fails with '%s; %s' combining the shared 'no active beads workspace found' message and diagHint() ('run bd where to inspect the resolved workspace, or bd init to create a new database'). This is the terminal error when neither the configured git-repo nor a workspace is available.","triggerScenarios":"Running backup export or auto-backup outside any beads workspace, or with backup.git-repo unset/invalid so the code falls through to FindBeadsDir which returns empty (no .beads found up the tree, BEADS_DIR unset/invalid).","commonSituations":"Running `bd backup export` in a plain git repo without bd init, deleted .beads directory, scripts run from $HOME or /tmp, misconfigured backup.git-repo triggering the fallback into a workspace-less cwd.","solutions":["Run 'bd init' in the repo to create the .beads workspace","Run 'bd where' (per the hint) to see how bd resolved the workspace and fix cwd/BEADS_DIR","Set a valid, writable backup.git-repo so the primary path is used instead of the fallback","cd into the workspace root before running backup commands"],"exampleFix":"// before\ncd /tmp && bd backup export\n// error: no active beads workspace found; run 'bd where' ...\n// after\ncd /path/to/bd-repo && bd backup export   # or: bd init","handlingStrategy":"validation","validationCode":"if beads.FindBeadsDir() == \"\" {\n    return errors.Errorf(\"no active beads workspace found; %s\", diagHint())\n}\n// then safe to call backupDir()","typeGuard":null,"tryCatchPattern":"dir, err := backupDir()\nif err != nil {\n    if strings.Contains(err.Error(), \"no active beads workspace found\") {\n        return fmt.Errorf(\"initialize first: bd init (hint included in error)\")\n    }\n    return err\n}","preventionTips":["Run bd init before any backup/export automation","Include a 'bd where' precondition check in scripts and CI","Keep .beads committed/checked out so clones are valid workspaces"],"tags":["go","workspace","backup"],"backgroundTag":"no-active-workspace","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}