{"record":{"id":"0b9ab7662d58d765","repo":"gastownhall/beads","slug":"dolt-remote-add-failed-s-w","errorCode":null,"errorMessage":"dolt remote add failed: %s: %w","messagePattern":"dolt remote add failed: (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/doltutil/remotes.go","lineNumber":168,"sourceCode":"\t}\n\treturn false\n}\n\n// AddCLIRemote adds a remote at the filesystem level via dolt CLI.\n// Remote mutation should normally go through SQL; this is reserved for the\n// local CLI mirror required by subprocess push/pull/fetch routing.\nfunc AddCLIRemote(dbPath, name, url string) error {\n\tif err := remotecache.ValidateRemoteName(name); err != nil {\n\t\treturn fmt.Errorf(\"invalid remote name: %w\", err)\n\t}\n\tif err := remotecache.ValidateRemoteURL(url); err != nil {\n\t\treturn fmt.Errorf(\"invalid remote URL: %w\", err)\n\t}\n\tcmd := exec.Command(\"dolt\", \"remote\", \"add\", name, url) // #nosec G204 -- validated argv\n\tcmd.Dir = dbPath\n\tout, err := cmd.CombinedOutput()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"dolt remote add failed: %s: %w\", strings.TrimSpace(string(out)), err)\n\t}\n\treturn nil\n}\n\n// RemoveCLIRemote removes a remote at the filesystem level via dolt CLI.\nfunc RemoveCLIRemote(dbPath, name string) error {\n\tif err := remotecache.ValidateRemoteName(name); err != nil {\n\t\treturn fmt.Errorf(\"invalid remote name: %w\", err)\n\t}\n\tcmd := exec.Command(\"dolt\", \"remote\", \"remove\", name) // #nosec G204 -- validated argv\n\tcmd.Dir = dbPath\n\tout, err := cmd.CombinedOutput()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"dolt remote remove failed: %s: %w\", strings.TrimSpace(string(out)), err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/doltutil/remotes.go#L150-L186","documentation":"After validating argv, AddCLIRemote executes `dolt remote add <name> <url>` with cmd.Dir set to dbPath. If the command exits non-zero or cannot start, the function returns dolt's combined stdout/stderr plus the exec error wrapped as \"dolt remote add failed\". This means the dolt subprocess itself rejected the operation or could not be run at all.","triggerScenarios":"Running AddCLIRemote/EnsureCLIRemote when: the `dolt` binary is not on PATH; dbPath is not an initialized dolt database (no .dolt directory); a remote with the same name already exists; the dolt version rejects the URL or flags; dbPath is not writable.","commonSituations":"Running bd sync in a repo where the embedded dolt DB was never initialized; a stale CLI remote left over from a previous sync causing an 'already exists' error; CI containers missing the dolt binary; a dolt upgrade/downgrade changing CLI behavior.","solutions":["Read the %s portion of the error message — it contains dolt's own diagnostic output for the failure","Verify `dolt` is installed and on PATH (`dolt version` succeeds)","Confirm dbPath holds an initialized dolt database (`dolt init` in dbPath if needed)","Run `dolt remote -v` in dbPath; if the remote already exists, remove it or let the idempotent EnsureCLIRemote reconcile it","Retry the sync once any environment issue is fixed"],"exampleFix":"// before\nif err := doltutil.EnsureCLIRemote(dbPath, \"origin\", url); err != nil {\n\treturn err // opaque failure when remote already exists\n}\n\n// after\nif doltutil.FindCLIRemote(dbPath, \"origin\") != url {\n\tif err := doltutil.EnsureCLIRemote(dbPath, \"origin\", url); err != nil {\n\t\treturn fmt.Errorf(\"sync remote setup: %w\", err)\n\t}\n}","handlingStrategy":"try-catch","validationCode":"if _, err := exec.LookPath(\"dolt\"); err != nil {\n\treturn fmt.Errorf(\"dolt binary required for CLI remote sync: %w\", err)\n}\nif _, err := os.Stat(filepath.Join(dbPath, \".dolt\")); err != nil {\n\treturn fmt.Errorf(\"%s is not an initialized dolt database\", dbPath)\n}","typeGuard":"func isDoltCLIError(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"dolt remote add failed:\")\n}","tryCatchPattern":"if err := doltutil.EnsureCLIRemote(dbPath, name, url); err != nil {\n\tif isDoltCLIError(err) {\n\t\t// dolt's combined output is embedded after the prefix — surface it to the user\n\t\treturn fmt.Errorf(\"remote setup failed; dolt said: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Ensure the dolt binary is installed and on PATH in every environment that runs bd sync","Initialize the dolt database (bd init / dolt init) before configuring remotes","Use the idempotent EnsureCLIRemote instead of calling AddCLIRemote directly so an existing remote is reconciled, not duplicated","Pin a known-good dolt version in CI to avoid CLI behavior changes"],"tags":["dolt","cli","subprocess","remote","exec"],"backgroundTag":"dolt-remote-add-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}