{"record":{"id":"11e689b28a91dc78","repo":"gastownhall/beads","slug":"failed-to-open-target-store-for-dry-run-w","errorCode":null,"errorMessage":"failed to open target store for dry-run: %w","messagePattern":"failed to open target store for dry-run: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/create.go","lineNumber":995,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"dry-run parent lookup requires an existing cached remote store for %s: %w\", repoPath, err)\n\t\t}\n\t\treturn store, nil\n\t}\n\n\ttargetPath := routing.ExpandPath(repoPath)\n\tbeadsDir := filepath.Join(targetPath, \".beads\")\n\tmetadataPath := filepath.Join(beadsDir, \"metadata.json\")\n\tif _, err := os.Stat(metadataPath); err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn nil, fmt.Errorf(\"target repo %s is not initialized; refusing to initialize it during dry-run\", targetPath)\n\t\t}\n\t\treturn nil, fmt.Errorf(\"failed to inspect target repo %s: %w\", targetPath, err)\n\t}\n\n\tstore, err := newPreviewStoreFromConfig(ctx, beadsDir)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open target store for dry-run: %w\", err)\n\t}\n\treturn store, nil\n}\n\n// isAmbiguousRepoTarget reports whether an explicit --repo value is a\n// bare/relative filesystem path (not absolute, not \"~/\"-prefixed). Such a\n// value silently resolves against the current working directory (see\n// routing.ExpandPath) rather than failing, so a misresolved value (e.g. a\n// typo) previously wrote a bead into a brand-new, disconnected database\n// instead of erroring (bd-8d3f).\nfunc isAmbiguousRepoTarget(repoFlagChanged bool, repoOverride string) bool {\n\treturn repoFlagChanged && !filepath.IsAbs(repoOverride) && !strings.HasPrefix(repoOverride, \"~/\")\n}\n\n// ensureBeadsDirForPath ensures a beads directory exists at the target path.\n// If the .beads directory doesn't exist, it creates it and initializes with\n// the same prefix as the source store (T010, T012: prefix inheritance).\n//","sourceCodeStart":977,"sourceCodeEnd":1013,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/create.go#L977-L1013","documentation":"After confirming the target repo is initialized, openDryRunTargetStore opens a read-only preview store via newPreviewStoreFromConfig(ctx, beadsDir). This error wraps any failure from that step — typically the Dolt database under .beads cannot be opened: corrupt database files, schema/version mismatch, missing or invalid metadata, or driver-level open failure. The repo passed the existence check but its store is not usable.","triggerScenarios":"bd create --dry-run --repo <local-path> where .beads/metadata.json exists but newPreviewStoreFromConfig fails: corrupted Dolt database in .beads, beads version wrote a newer schema/DB format than the installed binary supports, lock files left by a crashed process, or invalid metadata.json content.","commonSituations":"Mixed beads versions across machines (newer binary created the DB, older binary opens it); interrupted bd process leaving the Dolt database in a bad state; disk corruption or partially-synced .beads; manually edited metadata.json.","solutions":["Read the wrapped cause (%w) from newPreviewStoreFromConfig to see the exact open failure and address it.","Check beads version mismatch — run `bd --version`, upgrade the binary (or `bd upgrade`) so it can read the database, and run any advertised migration/doctor command.","Run `bd doctor` to detect and repair common database/metadata problems.","Restore .beads from git or re-sync with the remote (bd dolt pull) if the local database is corrupt.","As a last resort, re-init the repo (bd init) and re-import/sync, keeping the issues.jsonl export as the recovery source."],"exampleFix":"// before: DB created by newer beads version\nbd create --dry-run \"Task\" --repo .   // failed to open target store for dry-run: schema ...\n// after: upgrade binary and run doctor\nbd upgrade\nbd doctor\nbd create --dry-run \"Task\" --repo .","handlingStrategy":"try-catch","validationCode":"// Detect version skew and metadata validity before opening the store.\nout, err := exec.Command(\"bd\", \"--version\").Output()\nif err == nil && olderThanSupported(string(out)) {\n    return fmt.Errorf(\"bd binary is older than the repo's database; run `bd upgrade` first\")\n}\nif _, err := os.Stat(filepath.Join(repoPath, \".beads\", \"metadata.json\")); err != nil {\n    return fmt.Errorf(\"target metadata missing or unreadable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"store, err := openDryRunTargetStore(ctx, repoPath)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to open target store for dry-run\") {\n        fmt.Fprintf(os.Stderr, \"Cannot open target store: %v\\nRun `bd doctor` and `bd upgrade`; restore .beads from git if corrupt.\\n\", err)\n        os.Exit(1)\n    }\n    return err\n}","preventionTips":["Keep the bd binary version uniform across machines that touch the same repo.","Run `bd doctor` periodically and after any crashed/interrupted bd process.","Commit and regularly push .beads state so a corrupt local Dolt DB can be restored from git or the remote.","Never hand-edit metadata.json; let bd manage it."],"tags":["cli","dolt","database","dry-run"],"backgroundTag":"database-open-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}