{"record":{"id":"49318b966b8c130f","repo":"bytebase/bytebase","slug":"failed-to-get-user-id-by-email-v","errorCode":null,"errorMessage":"failed to get user id by email %v","messagePattern":"failed to get user id by email (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"backend/plugin/webhook/wecom/wecom.go","lineNumber":171,"sourceCode":"\twecom := getWecomConfig(webhookCtx.IMSetting)\n\tif wecom == nil {\n\t\treturn false\n\t}\n\tp, err := newProvider(wecom.GetCorpId(), wecom.GetAgentId(), wecom.GetSecret())\n\tif err != nil {\n\t\tslog.Error(\"failed to get wecom provider\", log.BBError(err))\n\t}\n\n\tctx := context.Background()\n\n\tfn := func() error {\n\t\tvar errs error\n\t\tvar users []string\n\n\t\tfor _, u := range webhookCtx.MentionEndUsers {\n\t\t\tuserID, err := p.getUserIDByEmail(ctx, u.Email)\n\t\t\tif err != nil {\n\t\t\t\terr = errors.Wrapf(err, \"failed to get user id by email %v\", u.Email)\n\t\t\t\tmultierr.AppendInto(&errs, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tusers = append(users, userID)\n\t\t}\n\t\tif len(users) == 0 {\n\t\t\terr := errors.Errorf(\"wecom dm: got 0 user id, errs: %v\", errs)\n\t\t\treturn backoff.Permanent(err)\n\t\t}\n\n\t\tif err := p.sendMessage(ctx, users, getMessageCard(webhookCtx)); err != nil {\n\t\t\terr = errors.Wrapf(err, \"failed to send message\")\n\t\t\tmultierr.AppendInto(&errs, err)\n\t\t}\n\n\t\treturn errs\n\t}\n","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/plugin/webhook/wecom/wecom.go#L153-L189","documentation":"When sending a direct message, the plugin resolves each mentioned end user's WeCom user ID from their email via getUserIDByEmail. This error wraps any per-user lookup failure and is accumulated into a multierror; the DM to that user is skipped. It indicates the email could not be mapped to a WeCom user (API error, user not in the workspace, or email mismatch).","triggerScenarios":"Post with webhookCtx.MentionEndUsers containing a user whose getUserIDByEmail call fails — user not found in the WeCom workspace, API rejection, or network failure during lookup.","commonSituations":"Bytebase user email differs from the email registered in WeCom; user left the company/WeCom workspace; WeCom API credentials lacking permission to look up contacts; transient API failures.","solutions":["Compare the Bytebase user email with the email configured in WeCom contacts — they must match exactly.","Confirm the user still exists and is active in the WeCom workspace.","Check WeCom contact-API permissions for the credentials used by the plugin.","Retry — the accumulated multierror means other users may still have been notified.","Exclude or update stale user records in MentionEndUsers."],"exampleFix":"// ensure emails match before sending\nmentionUsers := users.filter(u => wecomEmailExists(u.email))","handlingStrategy":"validation","validationCode":"// ensure emails are set and normalized before triggering the webhook\nfor _, u := range mentionEndUsers {\n    if u.Email == \"\" { continue /* or fix user record */ }\n    u.Email = strings.ToLower(strings.TrimSpace(u.Email))\n}","typeGuard":null,"tryCatchPattern":"if err := p.Post(ctx, webhookCtx); err != nil {\n    if strings.Contains(err.Error(), \"failed to get user id by email\") {\n        // fix that user's email in Bytebase or WeCom; other users were still notified\n    }\n}","preventionTips":["Keep Bytebase user emails identical to WeCom contact emails.","Sync user directories (SCIM/manual) regularly.","Remove offboarded users from mention lists.","Grant WeCom contact-read permissions to the integration.","Log per-user lookup failures distinctly from send failures."],"tags":["wecom","user-lookup","email","dm"],"backgroundTag":"user-not-found","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}