toeverything/AFFiNE · warning · MentionUserOneselfDenied

mention_user_oneself_denied

mention_user_oneself_denied

Error message

You can not mention yourself.

What it means

MentionUserOneselfDenied (code=mention_user_oneself_denied) thrown by the mention mutation when the target userId equals the current user's id. Mentions are for notifying OTHER users; self-mentions are rejected as a business rule. The check runs after schema parse and before any Doc.Update permission assertion.

Source

Thrown at packages/backend/server/src/core/notification/resolver.ts:57

  }

  @Mutation(() => ID, {
    description: 'mention user in a doc',
  })
  async mentionUser(
    @CurrentUser() me: UserType,
    @Args('input') input: MentionInput
  ) {
    const parsedInput = MentionNotificationCreateSchema.parse({
      userId: input.userId,
      body: {
        workspaceId: input.workspaceId,
        doc: input.doc,
        createdByUserId: me.id,
      },
    });
    if (parsedInput.userId === me.id) {
      throw new MentionUserOneselfDenied();
    }
    // currentUser can update the doc
    await this.ac
      .user(me.id)
      .doc(parsedInput.body.workspaceId, parsedInput.body.doc.id)
      .assert('Doc.Update');
    // mention user can read the doc
    if (
      !(await this.ac
        .user(parsedInput.userId)
        .doc(parsedInput.body.workspaceId, parsedInput.body.doc.id)
        .can('Doc.Read'))
    ) {
      throw new MentionUserDocAccessDenied({
        docId: parsedInput.body.doc.id,
      });
    }
    const notification = await this.service.createMention(parsedInput);

View on GitHub (pinned to 26c515e050)

Solutions

  1. Filter the current user out of the mention autocomplete list client-side.
  2. Disable the submit button when the selected user is the current user.
  3. On receiving this error, clear the selection and prompt the user to pick someone else.
  4. Treat code=mention_user_oneself_denied as a soft, expected error (not a bug to log).

Example fix

// before
if (parsedInput.userId === me.id) {
  throw new MentionUserOneselfDenied();
}

// client side — never send the self-mention
const candidates = users.filter(u => u.id !== me.id);
// and disable submit if somehow selected
if (selectedUserId === me.id) setSubmitDisabled(true);
Defensive patterns

Strategy: validation

Validate before calling

function assertNotSelfMention(meId: string, targetId: string) {
  if (meId === targetId) {
    throw new UserError('You cannot mention yourself');
  }
}

Type guard

function isSelfMentionDenied(e: unknown): boolean {
  return e instanceof Error && (e as any).code === 'mention_user_oneself_denied';
}

Try / catch

assertNotSelfMention(me.id, input.userId); // client-side guard
try {
  await resolver.createMention(me, input);
} catch (e) {
  if (isSelfMentionDenied(e)) { setMentionError('Pick a different user'); return; }
  throw e;
}

Prevention

When it happens

Trigger: Client submits a mention where input.userId === me.id — e.g. the user picks themselves from the mention autocomplete, or a paste/copy carried their own user reference.

Common situations: Autocomplete list includes the current user and the UI didn't filter them out. A 'reply' or 'assign' flow that defaults the target to the current user. Frontend bug building the userId.

Related errors


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