zed-industries/zed · warning
cannot add yourself as a contact
Error message
cannot add yourself as a contact
What it means
Thrown by the request_contact handler when responder_id equals the authenticated requester id. The server enforces that contact requests are always directed at a different user; the check happens before send_contact_request touches the database.
Source
Thrown at crates/collab/src/rpc.rs:2768
avatar_url: user.avatar_url,
github_login: user.github_login,
name: user.name,
})
.collect();
response.send(proto::UsersResponse { users })?;
Ok(())
}
/// Send a contact request to another user.
async fn request_contact(
request: proto::RequestContact,
response: Response<proto::RequestContact>,
session: MessageContext,
) -> Result<()> {
let requester_id = session.user_id();
let responder_id = UserId::from_proto(request.responder_id);
if requester_id == responder_id {
return Err(anyhow!("cannot add yourself as a contact"))?;
}
let notifications = session
.db()
.await
.send_contact_request(requester_id, responder_id)
.await?;
// Update outgoing contact requests of requester
let mut update = proto::UpdateContacts::default();
update.outgoing_requests.push(responder_id.to_proto());
for connection_id in session
.connection_pool()
.await
.user_connection_ids(requester_id)
{
session.peer.send(connection_id, update.clone())?;
}View on GitHub (pinned to bc538def45)
Solutions
- Filter the current user out of any picker/search results used to choose a contact target
- Validate responder_id != session user id on the client before sending RequestContact
- After account switching, rebuild cached identity state so 'self' is never offered as a target
Example fix
// before
client.request_contact(target_user_id).await?;
// after
if target_user_id == session.user_id() {
return Err(anyhow!("cannot add yourself as a contact"));
}
client.request_contact(target_user_id).await?; Defensive patterns
Strategy: validation
Validate before calling
// Never send a contact request to yourself.
if responder_id == session.user_id() {
return Err(anyhow!("cannot add yourself as a contact"));
}
client.request_contact(responder_id).await?; Type guard
fn is_self(session_user_id: UserId, target: UserId) -> bool {
session_user_id == target
} Try / catch
if let Err(err) = client.request_contact(target).await {
if err.to_string().contains("cannot add yourself") {
log::warn!("UI bug: self-contact attempted");
return Ok(()); // swallow; fix the picker that offered 'self'
}
return Err(err);
} Prevention
- Filter the current user out of contact search/picker results
- Rebuild cached identity after account switches
- Validate target ids client-side before every RequestContact
When it happens
Trigger: RequestContact RPC with your own user id (UI bug passing the logged-in identity as the target); contact-search flow that includes 'self' in its results; automated tests or scripts that hardcode a single user id for both fields.
Common situations: Search UI not filtering out the current user from the suggestion list; copied user id pasted into a 'add contact by id' field; client state confusion after switching accounts.
Related errors
- cannot call a user who isn't a contact
- not a collaborator on this project
- failed to ring user
- chat has been removed in the latest version of Zed
- unknown benchmark '{benchmark_id}' (valid: {valid})
AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16).
Data as JSON: /api/errors/397aece0f53dd3cb.
Report an issue: GitHub.