{"record":{"id":"a41cbffaef141315","repo":"apache/answer","slug":"s-activity-not-exist","errorCode":null,"errorMessage":"%s activity not exist","messagePattern":"(.+?) activity not exist","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/repo/activity/answer_repo.go","lineNumber":224,"sourceCode":"\t\t}\n\t}\n\treturn 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 (ar *AnswerActivityRepo) cancelActivities(session *xorm.Session, activities []*entity.Activity) (err error) {\n\tfor _, act := range activities {\n\t\tt := &entity.Activity{}\n\t\texist, err := session.ID(act.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\", act.ID))\n\t\t\treturn fmt.Errorf(\"%s activity not exist\", act.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\tact.Rank = 0\n\t\t}\n\t\tif _, err = session.ID(act.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 (ar *AnswerActivityRepo) changeUserRank(ctx context.Context, session *xorm.Session,","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/repo/activity/answer_repo.go#L206-L242","documentation":"Returned by cancelActivities in the answer activity repo when an expected activity record is not found in the database before cancellation. When cancelling answer-related activities, each activity must exist; if the ID lookup finds no row, this domain error aborts the cancellation. Unlike the migration errors it is a business-logic existence check, not a driver failure.","triggerScenarios":"Cancelling answer activities where the activity referenced by act.ID was deleted, never created, or belongs to another data set — the session/transaction Find reports exist=false for the activity ID.","commonSituations":"Data drift between the activity table and answer data (activities purged by cleanup jobs while answers remain); cancelling an answer twice after a partial rollback; environments where activity seeding was skipped.","solutions":["Verify the activity row with the logged act.ID exists in the activity table","Check for cleanup/purge jobs that delete activities referenced by answers","Make cancellation tolerant: skip missing activities instead of failing the whole operation if partial cancellation is acceptable","Re-run in a transaction so activity and answer changes stay consistent"],"exampleFix":"// before\nif !exist {\n    log.Error(fmt.Errorf(\"%s activity not exist\", act.ID))\n    return fmt.Errorf(\"%s activity not exist\", act.ID)\n}\n// after\nif !exist {\n    log.Warnf(\"activity %s not exist, skipping\", act.ID)\n    continue\n}","handlingStrategy":"validation","validationCode":"// before cancelling, confirm the activity exists\nvar count int64\nsession.Where(\"id = ?\", act.ID).Count(&entity.Activity{}, &count)\nif count == 0 {\n    log.Warnf(\"activity %s missing; skip cancel\", act.ID)\n    continue\n}","typeGuard":null,"tryCatchPattern":"if err := repo.CancelAnswerActivities(ctx, answerID); err != nil {\n    if strings.HasSuffix(err.Error(), \"activity not exist\") {\n        // tolerate missing activity: log and continue\n        log.Warnf(\"skip cancel: %v\", err)\n        return nil\n    }\n    return err\n}","preventionTips":["Delete activities and answers in the same transaction","Don't purge activity rows that are still referenced by answers","Make cancellation idempotent (skip already-cancelled/missing)","Reconcile orphaned answers against the activity table periodically"],"tags":["database","activity","data-consistency"],"backgroundTag":"activity-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"}