{"record":{"id":"c92ee5829425c70f","repo":"gastownhall/beads","slug":"createremote-s-w","errorCode":null,"errorMessage":"CreateRemote %s: %w","messagePattern":"CreateRemote (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/remote.go","lineNumber":44,"sourceCode":"func NewDoltRemoteUseCase(remoteRepo RemoteSQLRepository) DoltRemoteUseCase {\n\treturn &doltRemoteUseCaseImpl{remoteRepo: remoteRepo}\n}\n\ntype doltRemoteUseCaseImpl struct {\n\tremoteRepo RemoteSQLRepository\n}\n\nvar _ DoltRemoteUseCase = (*doltRemoteUseCaseImpl)(nil)\n\nfunc (u *doltRemoteUseCaseImpl) CreateRemote(ctx context.Context, name, url string) error {\n\tif name == \"\" {\n\t\treturn fmt.Errorf(\"CreateRemote: name must not be empty\")\n\t}\n\tif url == \"\" {\n\t\treturn fmt.Errorf(\"CreateRemote: url must not be empty\")\n\t}\n\tif err := u.remoteRepo.AddRemote(ctx, name, url); err != nil {\n\t\treturn fmt.Errorf(\"CreateRemote %s: %w\", name, err)\n\t}\n\treturn nil\n}\n\nfunc (u *doltRemoteUseCaseImpl) UpdateRemote(ctx context.Context, name, url string) error {\n\tif name == \"\" {\n\t\treturn fmt.Errorf(\"UpdateRemote: name must not be empty\")\n\t}\n\tif url == \"\" {\n\t\treturn fmt.Errorf(\"UpdateRemote: url must not be empty\")\n\t}\n\t// Dolt has no atomic remote update, so this is remove-then-add. Capture\n\t// the old URL first so a failed add can restore the remote instead of\n\t// leaving it deleted (bd-6dnrw.44 P3).\n\tvar oldURL string\n\tif remotes, err := u.remoteRepo.ListRemotes(ctx); err == nil {\n\t\tfor _, rem := range remotes {\n\t\t\tif rem.Name == name {","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/remote.go#L26-L62","documentation":"Wraps a failure from remoteRepo.AddRemote when adding a Dolt remote fails (internal/storage/domain/remote.go). The message includes the remote name being created; the underlying repository error is preserved with %w for errors.Is/As inspection.","triggerScenarios":"Calling CreateRemote with valid non-empty name/url when AddRemote fails: remote name already exists, underlying Dolt/SQL error, database locked or read-only, or context canceled.","commonSituations":"Re-running setup scripts that add an already-configured 'origin' remote; the Dolt database directory being read-only; another bd process holding the DB lock.","solutions":["Inspect the wrapped cause; if it's a 'remote already exists', remove it first or use UpdateRemote instead.","Run bd remote list (or equivalent) to check for an existing remote with that name.","Verify the database is writable and not locked by another process.","Retry with a fresh context if the error indicates cancellation/timeout."],"exampleFix":"// before\nerr := uc.CreateRemote(ctx, \"origin\", url)\nif err != nil { return err }\n// after\nerr := uc.CreateRemote(ctx, \"origin\", url)\nif err != nil {\n    if strings.Contains(fmt.Sprint(errors.Unwrap(err)), \"already\") {\n        return uc.UpdateRemote(ctx, \"origin\", url)\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"if name == \"\" || url == \"\" { return fmt.Errorf(\"name and url are required\") }","typeGuard":null,"tryCatchPattern":"err := uc.CreateRemote(ctx, name, url)\nif err != nil {\n    cause := fmt.Sprint(errors.Unwrap(err))\n    if strings.Contains(cause, \"already\") {\n        return uc.UpdateRemote(ctx, name, url)\n    }\n    return err\n}","preventionTips":["Check existing remotes before adding; use UpdateRemote for existing names.","Make setup scripts idempotent.","Ensure the database directory is writable before remote operations."],"tags":["go","database","remote","dolt"],"backgroundTag":"remote-add-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}