toeverything/AFFiNE · error · napi::Error
unknown workspace role: {role}
Error message
unknown workspace role: {role} What it means
An exhaustive-match fallback in parse_workspace_role: the function maps the strings 'external', 'member', 'admin', etc. to WorkspaceRole variants, and the wildcard arm fires for any other role string. It means the permission evaluation received a workspace role name from the database/request that has no corresponding WorkspaceRole variant — the interpolated value is the unrecognized role string; the faulting input is the role field of the permission input.
Source
Thrown at packages/backend/native/src/permission/candidates.rs:22
use super::{
actions::{
DOC_PREVIEW_ACTION, WORKSPACE_PREVIEW_ACTION, doc_actions_for_role, is_readonly_restricted_action, is_write_action,
workspace_actions_for_role,
},
types::{
Candidate, DocRole, PermissionDecisionRestrictionV1, PermissionDecisionSourceV1, PermissionDecisionV1,
PermissionDocInputV1, PermissionEvaluationInputV1, WorkspaceRole,
},
};
pub(super) fn parse_workspace_role(role: &str) -> anyhow::Result<WorkspaceRole> {
match role {
"external" => Ok(WorkspaceRole::External),
"member" => Ok(WorkspaceRole::Member),
"admin" => Ok(WorkspaceRole::Admin),
"owner" => Ok(WorkspaceRole::Owner),
_ => anyhow::bail!("unknown workspace role: {role}"),
}
}
pub(super) fn parse_doc_role(role: &str) -> anyhow::Result<DocRole> {
match role {
"none" => Ok(DocRole::None),
"external" => Ok(DocRole::External),
"reader" => Ok(DocRole::Reader),
"commenter" => Ok(DocRole::Commenter),
"editor" => Ok(DocRole::Editor),
"manager" => Ok(DocRole::Manager),
"owner" => Ok(DocRole::Owner),
_ => anyhow::bail!("unknown doc role: {role}"),
}
}
pub(super) fn role_name(role: impl Serialize) -> String {
serde_json::to_value(role)View on GitHub (pinned to 591f874dad)
Solutions
- Map the role string to a known workspace role before evaluation.
- Fix the caller to pass a valid role.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Raised when permission evaluation input contains a workspace role string other than external, member, admin, or owner.
Common situations: A caller passed an unrecognized workspace role. Ensure the role value comes from the documented set and is serialized in lowercase.
AI-assisted analysis of toeverything/AFFiNE@591f874dad (2026-08-18).
Data as JSON: /api/errors/4022bcb814319f79.
Report an issue: GitHub.