{"record":{"id":"0ca94c7216682fb3","repo":"mattermost-community/focalboard","slug":"cannot-find-user-w","errorCode":null,"errorMessage":"cannot find user: %w","messagePattern":"cannot find user: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/services/notify/plugindelivery/mention_deliver.go","lineNumber":19,"sourceCode":"// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.\n// See LICENSE.txt for license information.\n\npackage plugindelivery\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/mattermost/focalboard/server/services/notify\"\n\t\"github.com/mattermost/focalboard/server/utils\"\n\n\tmm_model \"github.com/mattermost/mattermost/server/public/model\"\n)\n\n// MentionDeliver notifies a user they have been mentioned in a blockv ia the plugin API.\nfunc (pd *PluginDelivery) MentionDeliver(mentionedUser *mm_model.User, extract string, evt notify.BlockChangeEvent) (string, error) {\n\tauthor, err := pd.api.GetUserByID(evt.ModifiedBy.UserID)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"cannot find user: %w\", err)\n\t}\n\n\tchannel, err := pd.getDirectChannel(evt.TeamID, mentionedUser.Id, pd.botID)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"cannot get direct channel: %w\", err)\n\t}\n\tlink := utils.MakeCardLink(pd.serverRoot, evt.Board.TeamID, evt.Board.ID, evt.Card.ID)\n\tboardLink := utils.MakeBoardLink(pd.serverRoot, evt.Board.TeamID, evt.Board.ID)\n\n\tpost := &mm_model.Post{\n\t\tUserId:    pd.botID,\n\t\tChannelId: channel.Id,\n\t\tMessage:   formatMessage(author.Username, extract, evt.Card.Title, link, evt.BlockChanged, boardLink, evt.Board.Title),\n\t}\n\n\tif _, err := pd.api.CreatePost(post); err != nil {\n\t\treturn \"\", err\n\t}","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/mattermost-community/focalboard/blob/a84bbb65e32edf972856b329417096ac413518e9/server/services/notify/plugindelivery/mention_deliver.go#L1-L37","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the wrapped cause to distinguish not-found vs API unavailable","Verify the modifying user still exists (GetUserByID manually) and is active","Ensure the plugin is properly connected to the Mattermost server (restart plugin if API calls fail at startup)","Purge notification events referencing deleted users"],"exampleFix":"// before\nauthor, err := pd.api.GetUserByID(evt.ModifiedBy.UserID)\nif err != nil {\n\treturn \"\", fmt.Errorf(\"cannot find user: %w\", err)\n}\n// after\nauthor, err := pd.api.GetUserByID(evt.ModifiedBy.UserID)\nif err != nil {\n\tif model.IsErrNotFound(err) {\n\t\treturn \"\", nil // skip mention delivery for deleted authors\n\t}\n\treturn \"\", fmt.Errorf(\"cannot find user: %w\", err)\n}","handlingStrategy":"validation","validationCode":"// before triggering mention flows, confirm the author exists\nif _, err := pd.api.GetUserByID(evt.ModifiedBy.UserID); err != nil {\n\t// skip or defer mention delivery\n}","typeGuard":"func authorExists(api UserAPI, userID string) bool {\n\t_, err := api.GetUserByID(userID)\n\treturn err == nil\n}","tryCatchPattern":"msg, err := pd.MentionDeliver(mentionedUser, extract, evt)\nif err != nil {\n\tif model.IsErrNotFound(err) {\n\t\treturn \"\", nil // author gone; skip\n\t}\n\treturn \"\", err\n}","preventionTips":["Clean up notify events when users are deleted/deactivated","Ensure the plugin is initialized before processing queued events","Match not-found vs API-unavailable causes with model.IsErrNotFound / errors.As","Check bot/system session validity if lookups fail broadly"],"tags":["go","mattermost-plugin","mentions","notifications"],"backgroundTag":"user-lookup-failed","analyzedSha":"a84bbb65e32edf972856b329417096ac413518e9","analyzedAt":"2026-08-30T09:22:20.720Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}