{"record":{"id":"556428930e2cb339","repo":"apache/answer","slug":"user-not-found","errorCode":null,"errorMessage":"user not found","messagePattern":"user not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/service/importer/importer_service.go","lineNumber":86,"sourceCode":"func (ip *ImporterService) NewImporterFunc() plugin.ImporterFunc {\n\treturn &ImporterFunc{importerService: ip}\n}\n\nfunc (ip *ImporterService) ImportQuestion(ctx context.Context, questionInfo plugin.QuestionImporterInfo) (err error) {\n\treq := &schema.QuestionAdd{}\n\terrFields := make([]*validator.FormErrorField, 0)\n\t// To limit rate, remove the following code from comment: Part 1/2\n\t// reject, rejectKey := ipc.rateLimitMiddleware.DuplicateRequestRejection(ctx, req)\n\t// if reject {\n\t// \treturn\n\t// }\n\tuserInfo, exist, err := ip.userCommon.GetByEmail(ctx, questionInfo.UserEmail)\n\tif err != nil {\n\t\tlog.Errorf(\"error: %v\", err)\n\t\treturn err\n\t}\n\tif !exist {\n\t\treturn fmt.Errorf(\"user not found\")\n\t}\n\n\t// To limit rate, remove the following code from comment: Part 2/2\n\t// defer func() {\n\t// \t// If status is not 200 means that the bad request has been returned, so the record should be cleared\n\t// \tif ctx.Writer.Status() != http.StatusOK {\n\t// \t\tipc.rateLimitMiddleware.DuplicateRequestClear(ctx, rejectKey)\n\t// \t}\n\t// }()\n\treq.UserID = userInfo.ID\n\treq.Title = questionInfo.Title\n\treq.Content = questionInfo.Content\n\treq.HTML = \"<p>\" + questionInfo.Content + \"</p>\"\n\treq.Tags = make([]*schema.TagItem, len(questionInfo.Tags))\n\tfor i, tag := range questionInfo.Tags {\n\t\treq.Tags[i] = &schema.TagItem{\n\t\t\tSlugName:    tag,\n\t\t\tDisplayName: tag,","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/service/importer/importer_service.go#L68-L104","documentation":"During question import, the service resolves the target user by email via userCommon.GetByEmail; if no user has that email it returns this error and the import aborts. The import format assigns questions to users by email address, so the users must pre-exist.","triggerScenarios":"ImportQuestion (reached via AddQuestion) with a questionInfo.UserEmail that matches no user row.","commonSituations":"Import files exported from another instance whose user emails differ; emails changed/case-mismatched since export; importing into a fresh site without creating the users first; trailing whitespace or casing differences in the CSV.","solutions":["Create the missing users (or register/import them) before running the question import.","Normalize emails in the import file (trim, lowercase) to match stored values.","Have the importer map unknown emails to a fallback/default user instead of failing.","Log which email failed so the operator can fix the data and retry."],"exampleFix":"// before\nif !exist {\n    return fmt.Errorf(\"user not found\")\n}\n// after\nif !exist {\n    return fmt.Errorf(\"user not found by email: %s\", questionInfo.UserEmail)\n}","handlingStrategy":"validation","validationCode":"email = strings.ToLower(strings.TrimSpace(questionInfo.UserEmail))\n_, exist, err := userCommon.GetByEmail(ctx, email)\nif err != nil {\n    return err\n}\nif !exist {\n    return fmt.Errorf(\"import aborted: no user with email %s; create users first\", email)\n}","typeGuard":"func importerHasUser(email string, users []entity.User) bool {\n    target := strings.ToLower(strings.TrimSpace(email))\n    for _, u := range users {\n        if strings.ToLower(u.Email) == target {\n            return true\n        }\n    }\n    return false\n}","tryCatchPattern":"err := importerService.ImportQuestion(ctx, req)\nif err != nil {\n    if strings.Contains(err.Error(), \"user not found\") {\n        return http.StatusBadRequest, \"create the referenced users before importing\"\n    }\n    return http.StatusInternalServerError, err.Error()\n}","preventionTips":["Create or import all users referenced by the import file first.","Normalize emails (trim + lowercase) in both storage and import data.","Dry-run the import to list unknown emails before applying it.","Map unknown emails to a designated fallback user if strict matching is not required."],"tags":["import","user-lookup","not-found"],"backgroundTag":"record-not-found","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}