{"record":{"id":"bd2d1cc8b6dfee3e","repo":"gastownhall/beads","slug":"failed-to-add-federation-peer-w","errorCode":null,"errorMessage":"failed to add federation peer: %w","messagePattern":"failed to add federation peer: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/dolt/credentials.go","lineNumber":304,"sourceCode":"\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to encrypt password: %w\", err)\n\t\t}\n\t}\n\n\t// Upsert the peer credentials\n\t_, err = s.execContext(ctx, `\n\t\tINSERT INTO federation_peers (name, remote_url, username, password_encrypted, sovereignty)\n\t\tVALUES (?, ?, ?, ?, ?)\n\t\tON DUPLICATE KEY UPDATE\n\t\t\tremote_url = VALUES(remote_url),\n\t\t\tusername = VALUES(username),\n\t\t\tpassword_encrypted = VALUES(password_encrypted),\n\t\t\tsovereignty = VALUES(sovereignty),\n\t\t\tupdated_at = CURRENT_TIMESTAMP\n\t`, peer.Name, peer.RemoteURL, peer.Username, encryptedPwd, peer.Sovereignty)\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to add federation peer: %w\", err)\n\t}\n\n\t// Also add the Dolt remote.\n\tif err := s.AddRemote(ctx, peer.Name, peer.RemoteURL); err != nil {\n\t\t// Ignore \"remote already exists\" errors\n\t\tif !strings.Contains(err.Error(), \"already exists\") {\n\t\t\treturn fmt.Errorf(\"failed to add dolt remote: %w\", err)\n\t\t}\n\t}\n\n\tif err := s.doltAddAndCommit(ctx, []string{\"federation_peers\"}, \"federation: add peer \"+peer.Name); err != nil {\n\t\treturn fmt.Errorf(\"failed to commit federation peer: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// GetFederationPeer retrieves a federation peer by name.","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/dolt/credentials.go#L286-L322","documentation":"This wraps the error from the SQL upsert INSERT ... ON DUPLICATE KEY UPDATE into the federation_peers table. It means the peer credentials row could not be written to the Dolt database — the peer was not added or updated.","triggerScenarios":"The INSERT/UPSERT statement fails: federation_peers table missing (schema not migrated), database connection lost, constraint violations, or the Dolt server rejecting the write (read-only replica, closed circuit breaker via withCircuitWrite).","commonSituations":"Running bd against a database created by an older version without the federation_peers table; external dolt-sql-server restarted or unreachable; disk full on the Dolt data directory; connecting with a read-only SQL user.","solutions":["Check the wrapped inner error for the root cause (connection refused vs unknown table vs permission denied).","Run schema migrations / `bd init` to create the federation_peers table if it doesn't exist.","Verify the Dolt server is reachable and the SQL user has write privileges on the database.","Check disk space and that the store isn't in a read-only or circuit-open state; retry after restoring connectivity."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Ensure the schema exists before writing\nif _, err := db.Query(\"SELECT 1 FROM federation_peers LIMIT 1\"); err != nil {\n    return fmt.Errorf(\"run bd init / migrate schema first: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := store.AddFederationPeer(ctx, peer); err != nil && strings.Contains(err.Error(), \"failed to add federation peer\") {\n    var netErr net.Error\n    if errors.As(err, &netErr) || strings.Contains(err.Error(), \"connection\") {\n        // retry after restoring Dolt server connectivity\n    }\n}","preventionTips":["Verify the Dolt server is up before bulk peer registration","Keep schema migrations current with bd upgrades","Monitor disk space on the Dolt data directory"],"tags":["go","database","sql","federation"],"backgroundTag":"database-write-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}