hcengineering/platform · error
Peer value already exists
Error message
Peer value already exists
What it means
createPeer in the CockroachDB implementation performs an INSERT ... ON CONFLICT DO NOTHING and then checks the affected row count. If zero rows were inserted, a peer record with the same key already exists, and it throws this plain Error. The method enforces peer uniqueness rather than silently overwriting or ignoring duplicates.
Source
Thrown at foundations/communication/packages/cockroach/src/db/peer.ts:59
const db: DbModel<Domain.Peer> = {
workspace_id: workspaceId,
card_id: cardId,
kind,
value,
extra,
created: date
}
if (options?.newValue === true) {
const { sql, values } = this.getInsertSql(Domain.Peer, db, [], {
conflictColumns: ['workspace_id', 'kind', 'value'],
conflictAction: 'DO NOTHING'
})
const result = await this.execute(sql, values, 'insert peer')
const count = result?.count ?? 0
if (count === 0) {
throw Error('Peer value already exists')
}
} else {
const { sql, values } = this.getInsertSql(Domain.Peer, db, [])
await this.execute(sql, values, 'insert peer')
}
}
async removePeer (workspaceId: WorkspaceUuid, cardId: CardID, kind: PeerKind, value: string): Promise<void> {
const filter: DbModelFilter<Domain.Peer> = [
{
column: 'workspace_id',
value: workspaceId
},
{
column: 'card_id',
value: cardId
},
{View on GitHub (pinned to 63e28dc964)
Solutions
- Check existence first (query the peer by key) and skip the insert if it already exists
- Wrap createPeer in try-catch and treat 'Peer value already exists' as success for idempotent re-registration
- Delete/upsert the existing peer row first (or use ON CONFLICT DO UPDATE) if replacing is intended
- Serialize creation (e.g., per-peer lock) to avoid concurrent duplicate inserts
Example fix
// before
try { await db.createPeer(peer) } catch (e) { /* crash */ }
// after
try {
await db.createPeer(peer)
} catch (e) {
if (!(e instanceof Error && e.message === 'Peer value already exists')) throw e
// treat as success: peer already registered
} Defensive patterns
Strategy: try-catch
Validate before calling
const existing = await db.findPeer(peer.key) if (existing) return existing // skip createPeer entirely
Type guard
function isDuplicatePeerError(e: unknown): e is Error {
return e instanceof Error && e.message === 'Peer value already exists'
} Try / catch
try {
await db.createPeer(peer)
} catch (e) {
if (isDuplicatePeerError(e)) return // idempotent re-registration
throw e
} Prevention
- Treat createPeer as non-idempotent; check existence or catch duplicates on retry
- Avoid concurrent createPeer calls for the same key (use per-key serialization)
- Delete or upsert old peer rows before re-registering a node
- Add retry logic that deduplicates on this specific error message
When it happens
Trigger: Calling createPeer (foundations/communication/packages/cockroach/src/db/peer.ts:59) when an INSERT into the Peer domain is a no-op due to ON CONFLICT DO NOTHING — i.e., a peer with the same unique key/value already exists in the table.
Common situations: Concurrent createPeer calls racing to insert the same peer (only one wins, the loser gets this error); retry logic re-invoking createPeer after a timeout when the first call actually succeeded; node re-registration without removing the old peer row; idempotency handling that assumes createPeer is safe to call twice.
Related errors
- Document ${documentName} already exists
- Failed to create channel for ${normalizedEmail} in space ${s
- Error cleaning the package install folder (${packageInstallF
- Error cleaning the package install folder (${packageInstallF
- adapter not provided: ${name}
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/0237ca96c154806a.
Report an issue: GitHub.