{"record":{"id":"67a945c818edc718","repo":"Tencent/WeKnora","slug":"join-request-not-found-67a945","errorCode":null,"errorMessage":"join request not found","messagePattern":"join request not found","errorType":"http","errorClass":null,"httpStatus":404,"severity":"error","filePath":"internal/application/service/organization.go","lineNumber":623,"sourceCode":"\t\treturn true\n\t}\n\treturn org.OwnerTenantID == tenantID\n}\n\n// generateInviteCode generates a random 16-character invite code\nfunc generateInviteCode() string {\n\tbytes := make([]byte, 8)\n\t_, _ = rand.Read(bytes)\n\treturn hex.EncodeToString(bytes)\n}\n\n// ----------------\n// Join Requests\n// ----------------\n\nvar (\n\tErrPendingRequestExists    = errors.New(\"pending request already exists\")\n\tErrJoinRequestNotFound     = errors.New(\"join request not found\")\n\tErrCannotUpgradeToSameRole = errors.New(\"cannot request upgrade to same or lower role\")\n\tErrAlreadyAdmin            = errors.New(\"tenant is already an admin\")\n)\n\n// SubmitJoinRequest submits a request for the caller's tenant to join an organization.\n// Dedup is now per-tenant: any user from a tenant already with a pending join\n// request is rejected (the same tenant can't queue two simultaneous joins).\nfunc (s *organizationService) SubmitJoinRequest(ctx context.Context, orgID string, userID string, tenantID uint64, message string, requestedRole types.OrgMemberRole) (*types.OrganizationJoinRequest, error) {\n\tlogger.Infof(ctx, \"Tenant %d (rep user %s) submitting join request for organization %s\", tenantID, userID, orgID)\n\n\texisting, err := s.orgRepo.GetPendingRequestByTenantAndType(ctx, orgID, tenantID, types.JoinRequestTypeJoin)\n\tif err == nil && existing != nil {\n\t\treturn nil, ErrPendingRequestExists\n\t}\n\n\torg, err := s.orgRepo.GetByID(ctx, orgID)\n\tif err != nil {\n\t\tif errors.Is(err, repository.ErrOrganizationNotFound) {","sourceCodeStart":605,"sourceCodeEnd":641,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/organization.go#L605-L641","documentation":"ErrJoinRequestNotFound is declared in both the service and repository layers (same message). The repository version is returned when a lookup maps gorm.ErrRecordNotFound to it; the service version is returned by lookups and by ReviewJoinRequest when the request's OrganizationID does not match the caller-supplied orgID. Callers should match with errors.Is.","triggerScenarios":"Looking up a join/upgrade request ID that does not exist, querying a pending request when none exists, or calling ReviewJoinRequest with an orgID that differs from the request's actual organization.","commonSituations":"Stale links after a request was deleted or purged, wrong org ID in admin review flows, cross-tenant ID confusion, or a request ID from another environment.","solutions":["Verify the join request ID and organization ID are correct and belong together.","Handle errors.Is(err, ErrJoinRequestNotFound) gracefully (e.g. show 'request no longer exists').","Refresh the request list instead of retrying a cached ID."],"exampleFix":"// before\nreq, err := svc.ReviewJoinRequest(ctx, orgID, requestID, true)\nif err != nil { return err }\n// after\nreq, err := svc.ReviewJoinRequest(ctx, orgID, requestID, true)\nif errors.Is(err, organization.ErrJoinRequestNotFound) {\n    return fmt.Errorf(\"request %s not found in org %s\", requestID, orgID)\n} else if err != nil { return err }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if errors.Is(err, organization.ErrJoinRequestNotFound) {\n    http.Error(w, \"join request not found\", http.StatusNotFound)\n    return\n}","preventionTips":["Verify org ID and request ID pairing before review calls.","Refresh stale links/queues after deletions.","Match with errors.Is since the sentinel exists in both service and repository packages."],"tags":["not-found","organization","go","gorm"],"backgroundTag":"record-not-found","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}