{"record":{"id":"d9af183a63deba19","repo":"gastownhall/beads","slug":"failed-to-initialize-remote-cache-w","errorCode":null,"errorMessage":"failed to initialize remote cache: %w","messagePattern":"failed to initialize remote cache: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/create.go","lineNumber":972,"sourceCode":"\t}\n\treturn t.Format(time.RFC3339)\n}\n\n// openDryRunTargetStore opens the store a `create --dry-run --repo <other>`\n// resolves --parent against. It is read-only on BOTH paths and must stay that\n// way: newDoltStoreFromConfig runs schema initialization on whatever it opens\n// and can rename a legacy hyphenated database and rewrite the target's\n// metadata.json on the way (GH#3231), so using it here would have a dry-run\n// mutate a repository the user only named as a lookup target — the same\n// migrate-at-open trap this preview policy exists to close, one repo over.\n// newPreviewStoreFromConfig is the non-mutating factory for a foreign\n// project (bd-6dnrw.32), relaxed for previews exactly as the root pre-run\n// relaxes the command's own store.\nfunc openDryRunTargetStore(ctx context.Context, repoPath string) (storage.DoltStorage, error) {\n\tif remotecache.IsRemoteURL(repoPath) {\n\t\tcache, err := remotecache.DefaultCache()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to initialize remote cache: %w\", err)\n\t\t}\n\t\t// The dry-run parent lookup only reads from this cached remote store.\n\t\t// Do not add writes here; dry-runs must not mutate cached remotes.\n\t\tstore, err := cache.OpenStore(ctx, repoPath, newPreviewStoreFromConfig)\n\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)","sourceCodeStart":954,"sourceCodeEnd":990,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/create.go#L954-L990","documentation":"This error is returned by openDryRunTargetStore in cmd/bd/create.go when `bd create --dry-run --repo <remote-url>` targets a remote URL but remotecache.DefaultCache() fails to initialize the local cache of remote Dolt databases. It wraps the underlying cause with %w so the real failure (cache dir creation, Dolt config, credentials) is preserved. The dry-run path must read the parent issue from a cached remote store without mutating it, and that cache could not be set up.","triggerScenarios":"Calling bd create with --dry-run where the --repo value passes remotecache.IsRemoteURL() (a remote URL, not a filesystem path) and the environment cannot initialize the default remote cache: e.g. the Dolt data dir cannot be created or opened, DoltGlobalSettings/config fails, or the remote-cache credentials/config are missing or corrupt.","commonSituations":"Running dry-run against a remote repo on a fresh machine or CI container where no remote cache has been pulled yet; read-only or missing HOME directory preventing cache-dir creation; corrupted ~/.beads remote cache state; restricted filesystem permissions.","solutions":["Read the wrapped cause (%w) in the error chain to see why DefaultCache() failed and fix that root cause (permissions, disk space, corrupt cache dir).","Run a non-dry-run `bd pull` or sync once to warm/populate the remote cache, then retry the dry-run.","Verify HOME and the beads config directory are writable and Dolt is correctly installed/configured.","If the target is actually local, pass a filesystem path instead of a remote URL so the non-remote branch of openDryRunTargetStore is used.","As a last resort, remove the corrupted remote cache directory so it is rebuilt on the next call."],"exampleFix":"// before: dry-run against a remote with no initialized cache\nbd create --dry-run \"Fix flake\" --repo dolt://remote/db\n// after: warm the cache first, then dry-run\nbd dolt pull\ncd example && bd create --dry-run \"Fix flake\" --repo dolt://remote/db","handlingStrategy":"try-catch","validationCode":"// Before a remote-URL dry-run, ensure Dolt and the beads config dir are usable.\nif remotecache.IsRemoteURL(repoPath) {\n    if _, err := exec.LookPath(\"dolt\"); err != nil {\n        return fmt.Errorf(\"dolt not installed; cannot dry-run against remote %s\", repoPath)\n    }\n    if d, err := os.UserHomeDir(); err != nil || d == \"\" {\n        return fmt.Errorf(\"HOME not set; remote cache unavailable\")\n    }\n}","typeGuard":"func isRemoteTarget(repoPath string) bool { return remotecache.IsRemoteURL(repoPath) }","tryCatchPattern":"store, err := openDryRunTargetStore(ctx, repoPath)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to initialize remote cache\") {\n        var cause error\n        if errors.As(err, &cause) || true { /* inspect %w chain */ }\n        fmt.Fprintf(os.Stderr, \"remote cache unusable: %v\\nRun `bd dolt pull` or fix cache dir permissions.\\n\", err)\n        os.Exit(1)\n    }\n    return err\n}","preventionTips":["Warm the remote cache (bd dolt pull) before running remote dry-runs, especially in fresh CI containers.","Ensure HOME is set and writable in the environment that runs bd.","Keep Dolt installed and on a supported version wherever dry-runs run.","Never run bd under sudo or as a different user than the one that owns the cache dir."],"tags":["cli","dolt","remote-cache","dry-run"],"backgroundTag":"remote-cache-init-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}