{"record":{"id":"11312e987d6d0159","repo":"gastownhall/beads","slug":"add-replacement-cli-remote-failed-w-additionall","errorCode":null,"errorMessage":"add replacement CLI remote failed: %w; additionally failed to restore previous URL %q: %v","messagePattern":"add replacement CLI remote failed: %w; additionally failed to restore previous URL %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/storage/doltutil/remotes.go","lineNumber":231,"sourceCode":"\tlock := cliRemoteLock(dbPath)\n\tlock.Lock()\n\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":213,"sourceCodeEnd":237,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/doltutil/remotes.go#L213-L237","documentation":"EnsureCLIRemote removed the existing CLI remote and then failed to add the replacement URL. It attempted to restore the previous URL with AddCLIRemote, and that restore ALSO failed. The error carries both the original add failure and the restore failure, meaning the named CLI remote is now MISSING from the local dolt directory — a doubly-broken state.","triggerScenarios":"Calling EnsureCLIRemote with a changed URL where: (1) the old remote exists and is removed, (2) dolt remote add <name> <new-url> fails (e.g. dolt CLI error, bad URL for dolt, locked repo), and (3) dolt remote add <name> <old-url> also fails (e.g. transient dolt failure, permissions, corrupted dolt dir).","commonSituations":"Migrating a remote to a new URL while the dolt database directory is corrupted or has permission problems; dolt version quirks rejecting URLs; concurrent processes interfering despite the lock; disk-full conditions during remote re-add.","solutions":["Read both wrapped errors: the first explains why the new URL failed, the second why the old URL could not be restored.","Manually re-add the remote: cd <dbPath> && dolt remote add <name> <old-url> (use the previous URL shown in the error message).","Verify with dolt remote -v that the remote exists again, then fix the target URL problem and re-run EnsureCLIRemote.","Check dolt CLI availability and directory permissions (dolt must be on PATH and dbPath writable)."],"exampleFix":"// after hitting the error, repair manually:\n// cd /path/to/db && dolt remote add origin https://old-url.example.com/repo\n// dolt remote -v  # confirm restored\n// then fix new URL and retry:\nerr := doltutil.EnsureCLIRemote(dbPath, \"origin\", validatedNewURL)","handlingStrategy":"try-catch","validationCode":"if doltutil.FindCLIRemote(dbPath, name) == \"\" && current != \"\" {\n    // remote was removed and not restored — repair before proceeding\n    _ = doltutil.AddCLIRemote(dbPath, name, savedURL)\n}","typeGuard":null,"tryCatchPattern":"saved := doltutil.FindCLIRemote(dbPath, name)\nif err := doltutil.EnsureCLIRemote(dbPath, name, newURL); err != nil {\n    if doltutil.FindCLIRemote(dbPath, name) == \"\" && saved != \"\" {\n        if rerr := doltutil.AddCLIRemote(dbPath, name, saved); rerr != nil {\n            return fmt.Errorf(\"remote lost; manual repair required: %w\", rerr)\n        }\n    }\n    return err\n}","preventionTips":["Record the current remote URL (FindCLIRemote) before mutating so you can repair after a doubly-failed EnsureCLIRemote.","After any EnsureCLIRemote error, run dolt remote -v to confirm the remote still exists.","Keep the dolt CLI on PATH and dbPath writable; check disk space before remote migrations."],"tags":["dolt","remote","state-corruption","restore-failed"],"backgroundTag":"remote-restore-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}