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

  1. Filter the current user out of any picker/search results used to choose a contact target
  2. Validate responder_id != session user id on the client before sending RequestContact
  3. 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

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


AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16). Data as JSON: /api/errors/397aece0f53dd3cb. Report an issue: GitHub.