mattermost-community/focalboard · error

cannot find user: %w

Error message

cannot find user: %w

What it means

MentionDeliver returns this error when fetching the author (the user who modified the block, evt.ModifiedBy.UserID) via the Mattermost plugin API GetUserByID fails. It means the mention notification cannot be built because the author's profile is unavailable. The underlying plugin API error is wrapped with %w.

Source

Thrown at server/services/notify/plugindelivery/mention_deliver.go:19

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

package plugindelivery

import (
	"fmt"

	"github.com/mattermost/focalboard/server/services/notify"
	"github.com/mattermost/focalboard/server/utils"

	mm_model "github.com/mattermost/mattermost/server/public/model"
)

// MentionDeliver notifies a user they have been mentioned in a blockv ia the plugin API.
func (pd *PluginDelivery) MentionDeliver(mentionedUser *mm_model.User, extract string, evt notify.BlockChangeEvent) (string, error) {
	author, err := pd.api.GetUserByID(evt.ModifiedBy.UserID)
	if err != nil {
		return "", fmt.Errorf("cannot find user: %w", err)
	}

	channel, err := pd.getDirectChannel(evt.TeamID, mentionedUser.Id, pd.botID)
	if err != nil {
		return "", fmt.Errorf("cannot get direct channel: %w", err)
	}
	link := utils.MakeCardLink(pd.serverRoot, evt.Board.TeamID, evt.Board.ID, evt.Card.ID)
	boardLink := utils.MakeBoardLink(pd.serverRoot, evt.Board.TeamID, evt.Board.ID)

	post := &mm_model.Post{
		UserId:    pd.botID,
		ChannelId: channel.Id,
		Message:   formatMessage(author.Username, extract, evt.Card.Title, link, evt.BlockChanged, boardLink, evt.Board.Title),
	}

	if _, err := pd.api.CreatePost(post); err != nil {
		return "", err
	}

View on GitHub (pinned to a84bbb65e3)

Solutions

  1. Check the wrapped cause to distinguish not-found vs API unavailable
  2. Verify the modifying user still exists (GetUserByID manually) and is active
  3. Ensure the plugin is properly connected to the Mattermost server (restart plugin if API calls fail at startup)
  4. Purge notification events referencing deleted users

Example fix

// before
author, err := pd.api.GetUserByID(evt.ModifiedBy.UserID)
if err != nil {
	return "", fmt.Errorf("cannot find user: %w", err)
}
// after
author, err := pd.api.GetUserByID(evt.ModifiedBy.UserID)
if err != nil {
	if model.IsErrNotFound(err) {
		return "", nil // skip mention delivery for deleted authors
	}
	return "", fmt.Errorf("cannot find user: %w", err)
}
Defensive patterns

Strategy: validation

Validate before calling

// before triggering mention flows, confirm the author exists
if _, err := pd.api.GetUserByID(evt.ModifiedBy.UserID); err != nil {
	// skip or defer mention delivery
}

Type guard

func authorExists(api UserAPI, userID string) bool {
	_, err := api.GetUserByID(userID)
	return err == nil
}

Try / catch

msg, err := pd.MentionDeliver(mentionedUser, extract, evt)
if err != nil {
	if model.IsErrNotFound(err) {
		return "", nil // author gone; skip
	}
	return "", err
}

Prevention

When it happens

Trigger: A block-change event mentions a user and MentionDeliver runs, but GetUserByID(evt.ModifiedBy.UserID) fails — the modifying user was deleted/deactivated, the ID is from a different instance, or the plugin API (Mattermost server) is unreachable.

Common situations: User accounts removed after leaving the team while their old edits trigger notifications; plugin not fully initialized against the Mattermost server (race at startup); cross-instance data imports with stale user IDs; session/API token problems for the bot.

Related errors


AI-assisted analysis of mattermost-community/focalboard@a84bbb65e3 (2026-08-30). Data as JSON: /api/errors/0ca94c7216682fb3. Report an issue: GitHub.