apache/answer · error
user not found
Error message
user not found
What it means
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.
Source
Thrown at internal/service/importer/importer_service.go:86
func (ip *ImporterService) NewImporterFunc() plugin.ImporterFunc {
return &ImporterFunc{importerService: ip}
}
func (ip *ImporterService) ImportQuestion(ctx context.Context, questionInfo plugin.QuestionImporterInfo) (err error) {
req := &schema.QuestionAdd{}
errFields := make([]*validator.FormErrorField, 0)
// To limit rate, remove the following code from comment: Part 1/2
// reject, rejectKey := ipc.rateLimitMiddleware.DuplicateRequestRejection(ctx, req)
// if reject {
// return
// }
userInfo, exist, err := ip.userCommon.GetByEmail(ctx, questionInfo.UserEmail)
if err != nil {
log.Errorf("error: %v", err)
return err
}
if !exist {
return fmt.Errorf("user not found")
}
// To limit rate, remove the following code from comment: Part 2/2
// defer func() {
// // If status is not 200 means that the bad request has been returned, so the record should be cleared
// if ctx.Writer.Status() != http.StatusOK {
// ipc.rateLimitMiddleware.DuplicateRequestClear(ctx, rejectKey)
// }
// }()
req.UserID = userInfo.ID
req.Title = questionInfo.Title
req.Content = questionInfo.Content
req.HTML = "<p>" + questionInfo.Content + "</p>"
req.Tags = make([]*schema.TagItem, len(questionInfo.Tags))
for i, tag := range questionInfo.Tags {
req.Tags[i] = &schema.TagItem{
SlugName: tag,
DisplayName: tag,View on GitHub (pinned to 3b9f137061)
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.
Example fix
// before
if !exist {
return fmt.Errorf("user not found")
}
// after
if !exist {
return fmt.Errorf("user not found by email: %s", questionInfo.UserEmail)
} Defensive patterns
Strategy: validation
Validate before calling
email = strings.ToLower(strings.TrimSpace(questionInfo.UserEmail))
_, exist, err := userCommon.GetByEmail(ctx, email)
if err != nil {
return err
}
if !exist {
return fmt.Errorf("import aborted: no user with email %s; create users first", email)
} Type guard
func importerHasUser(email string, users []entity.User) bool {
target := strings.ToLower(strings.TrimSpace(email))
for _, u := range users {
if strings.ToLower(u.Email) == target {
return true
}
}
return false
} Try / catch
err := importerService.ImportQuestion(ctx, req)
if err != nil {
if strings.Contains(err.Error(), "user not found") {
return http.StatusBadRequest, "create the referenced users before importing"
}
return http.StatusInternalServerError, err.Error()
} Prevention
- 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.
When it happens
Trigger: ImportQuestion (reached via AddQuestion) with a questionInfo.UserEmail that matches no user row.
Common situations: 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.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
AI-assisted analysis of apache/answer@3b9f137061 (2026-09-05).
Data as JSON: /api/errors/556428930e2cb339.
Report an issue: GitHub.