{"record":{"id":"aff6e7b7f7852428","repo":"gastownhall/beads","slug":"add-replacement-cli-remote-failed-previous-url-q","errorCode":null,"errorMessage":"add replacement CLI remote failed; previous URL %q restored: %w","messagePattern":"add replacement CLI remote failed; previous URL %q restored: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/doltutil/remotes.go","lineNumber":233,"sourceCode":"\tdefer lock.Unlock()\n\n\tcurrent := FindCLIRemote(dbPath, name)\n\tif RemoteURLsMatch(current, url) {\n\t\treturn nil\n\t}\n\tif current != \"\" {\n\t\tif err := RemoveCLIRemote(dbPath, name); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\tif err := AddCLIRemote(dbPath, name, url); err != nil {\n\t\tif current == \"\" {\n\t\t\treturn err\n\t\t}\n\t\tif restoreErr := AddCLIRemote(dbPath, name, current); restoreErr != nil {\n\t\t\treturn fmt.Errorf(\"add replacement CLI remote failed: %w; additionally failed to restore previous URL %q: %v\", err, current, restoreErr)\n\t\t}\n\t\treturn fmt.Errorf(\"add replacement CLI remote failed; previous URL %q restored: %w\", current, err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":215,"sourceCodeEnd":237,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/doltutil/remotes.go#L215-L237","documentation":"EnsureCLIRemote failed to add the replacement URL, but successfully restored the previous URL via AddCLIRemote. This error reports the original add failure while assuring the caller that the CLI remote still points at the old URL — the system is back in its prior, consistent state.","triggerScenarios":"Calling EnsureCLIRemote with a changed URL where dolt remote add <name> <new-url> fails (dolt CLI error, invalid URL for dolt, transient failure) but re-adding the old URL succeeds.","commonSituations":"Pointing the remote at a new URL that dolt rejects (bad format, unreachable host baked into URL) while the old remote remains valid; typos when migrating remotes; dolt CLI transient failures.","solutions":["The previous URL was restored — no repair is needed; fix the new URL.","Check the wrapped inner error for dolt's reason (shown via 'dolt remote add failed: <output>').","Validate the new URL with remotecache.ValidateRemoteURL and confirm the target repo exists/is reachable, then call EnsureCLIRemote again.","If migrating intentionally, run dolt remote add <name> <new-url> manually in dbPath to see the raw CLI error."],"exampleFix":"// before (URL dolt rejects)\nerr := doltutil.EnsureCLIRemote(dbPath, \"origin\", \"htp:/bad-url/repo\")\n// after\nnewURL := \"https://doltremoteapi.dolthub.com/org/repo\"\nif err := remotecache.ValidateRemoteURL(newURL); err == nil {\n    err = doltutil.EnsureCLIRemote(dbPath, \"origin\", newURL)\n}","handlingStrategy":"retry","validationCode":"if err := remotecache.ValidateRemoteURL(newURL); err != nil {\n    return fmt.Errorf(\"skip migration, URL invalid: %w\", err)\n}\nerr := doltutil.EnsureCLIRemote(dbPath, name, newURL)","typeGuard":null,"tryCatchPattern":"err := doltutil.EnsureCLIRemote(dbPath, name, newURL)\nif err != nil {\n    var wrapped *fmt.WrapError\n    _ = err // old URL was restored; safe to fix newURL and retry\n    if strings.Contains(err.Error(), \"restored\") {\n        // retry after correcting newURL\n        err = doltutil.EnsureCLIRemote(dbPath, name, correctedURL)\n    }\n}","preventionTips":["Validate and test the new remote URL (network reachability, correct scheme) before switching.","Treat 'restored' in this error as a signal the state is safe — fix the URL and simply retry.","Avoid changing remote URLs during concurrent dolt operations."],"tags":["dolt","remote","rollback","validation"],"backgroundTag":"remote-url-migration-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}