{"record":{"id":"68cae57a781b6cbf","repo":"apache/answer","slug":"s-activity-not-exist-68cae5","errorCode":null,"errorMessage":"%s activity not exist","messagePattern":"(.+?) activity not exist","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/repo/activity/vote_repo.go","lineNumber":373,"sourceCode":"\t\t}\n\t}\n\treturn newAct, nil\n}\n\n// cancelActivities cancel activities\n// If this activity is already cancelled, set activity rank to 0\n// So after this function, the activity rank will be correct for update user rank\nfunc (vr *VoteRepo) cancelActivities(session *xorm.Session, activities []*entity.Activity) (err error) {\n\tfor _, activity := range activities {\n\t\tt := &entity.Activity{}\n\t\texist, err := session.ID(activity.ID).Get(t)\n\t\tif err != nil {\n\t\t\tlog.Error(err)\n\t\t\treturn err\n\t\t}\n\t\tif !exist {\n\t\t\tlog.Error(fmt.Errorf(\"%s activity not exist\", activity.ID))\n\t\t\treturn fmt.Errorf(\"%s activity not exist\", activity.ID)\n\t\t}\n\t\t//  If this activity is already cancelled, set activity rank to 0\n\t\tif t.Cancelled == entity.ActivityCancelled {\n\t\t\tactivity.Rank = 0\n\t\t}\n\t\tif _, err = session.ID(activity.ID).Cols(\"cancelled\", \"cancelled_at\").\n\t\t\tUpdate(&entity.Activity{\n\t\t\t\tCancelled:   entity.ActivityCancelled,\n\t\t\t\tCancelledAt: time.Now(),\n\t\t\t}); err != nil {\n\t\t\tlog.Error(err)\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (vr *VoteRepo) getExistActivity(ctx context.Context, op *schema.VoteOperationInfo) ([]*entity.Activity, error) {","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/repo/activity/vote_repo.go#L355-L391","documentation":"Raised in cancelActivities when an activity to be cancelled cannot be loaded by its ID: exist is false and the repo logs and returns this error, aborting the cancellation transaction. It indicates the activity ID supplied for cancellation does not match any row.","triggerScenarios":"Calling cancelActivities with an activity.ID that is not in the activities table (already hard-deleted, wrong ID, or from a different database).","commonSituations":"Double-clicking a cancel action after the activity was already removed; stale admin UI listing deleted activities; importing IDs across environments.","solutions":["Confirm the activity ID exists: SELECT id FROM activities WHERE id = <id>;","Make the caller check existence (or treat missing as already-cancelled) before invoking cancel.","Remove stale references in the UI/API payloads; refresh the activity list.","If soft-deletes are used, ensure the query isn't filtering out cancelled/deleted rows unintentionally."],"exampleFix":"// before\nif !exist {\n    log.Error(fmt.Errorf(\"%s activity not exist\", activity.ID))\n    return fmt.Errorf(\"%s activity not exist\", activity.ID)\n}\n// after\nif !exist {\n    log.Warnf(\"cancel skipped, activity %s not exist\", activity.ID)\n    return nil // or ErrActivityNotFound for the caller to handle idempotently\n}","handlingStrategy":"try-catch","validationCode":"var act entity.Activity\nexist, err := db.ID(activityID).Get(&act)\nif err == nil && !exist {\n    // treat as already-cancelled / report not found to the UI before calling cancel\n    return fmt.Errorf(\"activity %d not found, cannot cancel\", activityID)\n}","typeGuard":"func activityExists(rows []entity.Activity, id int64) bool {\n    for _, a := range rows {\n        if a.ID == id {\n            return true\n        }\n    }\n    return false\n}","tryCatchPattern":"err := activityService.CancelActivities(ctx, ids)\nif err != nil {\n    if strings.Contains(err.Error(), \"activity not exist\") {\n        // idempotent: already gone, refresh list\n        return nil\n    }\n    return err\n}","preventionTips":["Refresh the admin activity list before issuing cancels; drop stale IDs.","Make cancel idempotent in callers (missing = already cancelled).","Avoid hard-deleting activities that admin UI may still reference.","Log the activity ID in the error (it already does) and surface it to support."],"tags":["database","activity","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-14T00:17:10.932Z"}