toeverything/AFFiNE · error · DocDefaultRoleCanNotBeOwner
doc_default_role_can_not_be_owner
doc_default_role_can_not_be_owner
Error message
Doc default role can not be owner.
What it means
Thrown by updateDocDefaultRole when input.role === DocRole.Owner. The 'default role' is the role auto-applied to users who can reach the doc without an explicit grant; ownership is a singular, per-user capability (transfer/manage authority) and must never be a blanket default. Rejecting Owner up front (invalid_input) avoids creating docs where every reader is an owner.
Source
Thrown at packages/backend/server/src/core/workspaces/resolvers/doc.ts:862
workspaceId: input.workspaceId,
docId: input.docId,
});
this.logger.log(`Update doc user role (${JSON.stringify(info)})`);
}
return true;
}
@Mutation(() => Boolean)
async updateDocDefaultRole(
@CurrentUser() user: CurrentUser,
@Args('input') input: UpdateDocDefaultRoleInput
) {
if (input.role === DocRole.Owner) {
this.logger.debug(
`Doc default role can not be owner (${JSON.stringify(input)})`
);
throw new DocDefaultRoleCanNotBeOwner();
}
const pairs = {
spaceId: input.workspaceId,
docId: input.docId,
};
if (input.workspaceId === input.docId) {
this.logger.error(
'Expect to update page default role, but it is a workspace',
pairs
);
throw new ExpectToUpdateDocUserRole(
pairs,
'Expect doc not to be workspace'
);
}
try {
await this.ac.user(user.id).doc(input).assert('Doc.Users.Manage');
} catch (error) {View on GitHub (pinned to 26c515e050)
Solutions
- Choose a non-owner DocRole for the default (Viewer, Commenter, or Editor).
- Filter DocRole.Owner out of the default-role picker in the UI.
- To grant ownership to a specific user, call updateDocUserRole with role: DocRole.Owner instead.
Example fix
// before
updateDocDefaultRole({ workspaceId, docId, role: DocRole.Owner });
// after
updateDocDefaultRole({ workspaceId, docId, role: DocRole.Editor }); Defensive patterns
Strategy: validation
Validate before calling
function isValidDefaultRole(role: DocRole): boolean {
return role !== DocRole.Owner;
}
if (!isValidDefaultRole(input.role)) throw new Error('Default role cannot be Owner'); Type guard
function isNonOwnerRole(role: DocRole): boolean {
return role !== DocRole.Owner;
} Prevention
- Exclude DocRole.Owner from default-role pickers.
- Map 'make owner' to updateDocUserRole(role: Owner), not updateDocDefaultRole.
- Serialize DocRole by name, not index, to avoid accidental Owner selection.
When it happens
Trigger: Calling mutation updateDocDefaultRole with UpdateDocDefaultRoleInput.role set to DocRole.Owner.
Common situations: A role picker component that lists all DocRole values is reused for the default-role selector; the enum is serialized by index and the highest index (Owner) is selected by default; a UI 'make everyone admin' shortcut mistakenly maps to Owner.
Related errors
- expect_to_revoke_doc_user_roles
- expect_to_update_doc_user_role
- expect_to_grant_doc_user_roles
- action_forbidden_on_non_team_workspace
- bad_request
AI-assisted analysis of toeverything/AFFiNE@26c515e050 (2026-08-12).
Data as JSON: /api/errors/084a06c771b91025.
Report an issue: GitHub.