{"record":{"id":"f7de1fdcd921e473","repo":"zed-industries/zed","slug":"user-is-not-a-channel-admin-or-channel-does-not-ex","errorCode":null,"errorMessage":"user is not a channel admin or channel does not exist","messagePattern":"user is not a channel admin or channel does not exist","errorType":"validation","errorClass":"Error::Internal","httpStatus":null,"severity":"error","filePath":"crates/collab/src/db/queries/channels.rs","lineNumber":746,"sourceCode":"        })\n        .await\n    }\n\n    /// Returns whether the given user is an admin in the specified channel.\n    pub async fn check_user_is_channel_admin(\n        &self,\n        channel: &channel::Model,\n        user_id: UserId,\n        tx: &DatabaseTransaction,\n    ) -> Result<ChannelRole> {\n        let role = self.channel_role_for_user(channel, user_id, tx).await?;\n        match role {\n            Some(ChannelRole::Admin) => Ok(role.unwrap()),\n            Some(ChannelRole::Member)\n            | Some(ChannelRole::Talker)\n            | Some(ChannelRole::Banned)\n            | Some(ChannelRole::Guest)\n            | None => Err(anyhow!(\n                \"user is not a channel admin or channel does not exist\"\n            ))?,\n        }\n    }\n\n    /// Returns whether the given user is a member of the specified channel.\n    pub async fn check_user_is_channel_member(\n        &self,\n        channel: &channel::Model,\n        user_id: UserId,\n        tx: &DatabaseTransaction,\n    ) -> Result<ChannelRole> {\n        let channel_role = self.channel_role_for_user(channel, user_id, tx).await?;\n        match channel_role {\n            Some(ChannelRole::Admin) | Some(ChannelRole::Member) => Ok(channel_role.unwrap()),\n            Some(ChannelRole::Banned)\n            | Some(ChannelRole::Guest)\n            | Some(ChannelRole::Talker)","sourceCodeStart":728,"sourceCodeEnd":764,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/collab/src/db/queries/channels.rs#L728-L764","documentation":"Thrown by check_user_is_channel_admin (crates/collab/src/db/queries/channels.rs:746): the user's ChannelRole resolved via channel_role_for_user is Member, Talker, Guest, Banned, or None (no membership row) — only Admin passes. Guards every admin-only operation (rename, delete, move, role changes).","triggerScenarios":"A non-admin member/guest/talker/banned user calling delete_channel, rename_channel, move_channel, or remove_channel_member; calling any of these after the user's admin role was downgraded; calling with a user id that has no channel_member row at all (None arm).","commonSituations":"Role downgraded while the client kept an admin UI visible; a guest granted Talker expecting admin rights; org admins (server-level) assuming channel-admin powers — server admin is a different flag and does not pass this check.","solutions":["Promote the user to ChannelRole::Admin for that channel before retrying (an existing admin must change the role)","Ensure the client disables/hides admin actions based on the role delivered in membership_update events, and re-checks on role change","Confirm you are passing the acting user's id (admin_id) and not the target's id — a swapped argument produces exactly this error"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Client-side gate for admin actions\nfn can_admin(role: Option<ChannelRole>) -> bool {\n    matches!(role, Some(ChannelRole::Admin))\n}\n\nif !can_admin(my_role) {\n    return Err(anyhow!(\"admin role required\"));\n}","typeGuard":"fn is_channel_admin(role: Option<ChannelRole>) -> bool {\n    role == Some(ChannelRole::Admin)\n}","tryCatchPattern":"match db.delete_channel(channel_id, admin_id).await {\n    Ok(v) => Ok(v),\n    Err(err) if err.to_string().contains(\"not a channel admin\") => {\n        Err(anyhow!(\"ask a channel admin to perform this action\"))\n    }\n    Err(err) => Err(err),\n}","preventionTips":["Hide rename/delete/move/role-change UI unless the user's role for that channel is Admin","Update cached roles on every membership_update event","Remember server-level admin and channel Admin are different — only the latter passes this check"],"tags":["collab","channels","authorization","roles"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}