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

  1. Choose a non-owner DocRole for the default (Viewer, Commenter, or Editor).
  2. Filter DocRole.Owner out of the default-role picker in the UI.
  3. 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

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


AI-assisted analysis of toeverything/AFFiNE@26c515e050 (2026-08-12). Data as JSON: /api/errors/084a06c771b91025. Report an issue: GitHub.