{"record":{"id":"bce084aedcaf24b0","repo":"gotify/server","slug":"user-with-id-d-not-found","errorCode":null,"errorMessage":"user with id %d not found","messagePattern":"user with id (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/manager.go","lineNumber":270,"sourceCode":"\t\treturn fmt.Errorf(\"plugin with module path %s is present at least twice\", modulePath)\n\t}\n\tm.plugins[modulePath] = compatPlugin\n\treturn nil\n}\n\n// InitializeForUserID initializes all plugin instances for a given user.\nfunc (m *Manager) InitializeForUserID(userID uint) error {\n\tm.mutex.Lock()\n\tdefer m.mutex.Unlock()\n\n\tuser, err := m.db.GetUserByID(userID)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif user != nil {\n\t\treturn m.initializeForUser(*user)\n\t}\n\treturn fmt.Errorf(\"user with id %d not found\", userID)\n}\n\nfunc (m *Manager) initializeForUser(user model.User) error {\n\tuserCtx := compat.UserContext{\n\t\tID:    user.ID,\n\t\tName:  user.Name,\n\t\tAdmin: user.Admin,\n\t}\n\n\tfor _, p := range m.plugins {\n\t\tif err := m.initializeSingleUserPlugin(userCtx, p); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tapps, err := m.db.GetApplicationsByUser(user.ID)\n\tif err != nil {\n\t\treturn err","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/gotify/server/blob/14bfc256276775c425f988d621dccfe705de18ac/plugin/manager.go#L252-L288","documentation":"InitializeForUserID looks up the user by ID and, when the storage returns no user (nil) and no error, returns 'user with id %d not found'. It guards the per-user plugin initialization against stale or invalid user IDs.","triggerScenarios":"Calling InitializeForUserID with a userID that does not exist in the user storage — typically a deleted user, or a user ID from a stale session/token.","commonSituations":"Race where a user is deleted while their plugin sessions are being initialized, or tests/bots passing synthetic user IDs.","solutions":["Verify the user ID exists before calling InitializeForUserID","Handle the error by skipping plugin initialization for the missing user","Clean up plugin enable/disable config entries when deleting users"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"u, err := userStorage.GetUserByID(userID)\nif err != nil || u == nil {\n    log.Printf(\"user %d does not exist; skipping plugin init\", userID)\n    return\n}","typeGuard":null,"tryCatchPattern":"if err := mgr.InitializeForUserID(uid); err != nil {\n    if strings.Contains(err.Error(), \"not found\") {\n        log.Printf(\"stale user id %d, skipping\", uid)\n        return nil\n    }\n    return err\n}","preventionTips":["Delete plugin config entries when removing users","Re-check user existence before deferred initialization tasks","Use foreign keys/cascades between users and plugin settings"],"tags":["plugin","user","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"14bfc256276775c425f988d621dccfe705de18ac","analyzedAt":"2026-09-05T12:52:36.781Z","contentChangedAt":"2026-09-05T12:52:36.781Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}