apache/answer · error

%s activity not exist

Error message

%s activity not exist

What it means

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.

Source

Thrown at internal/repo/activity/vote_repo.go:373

		}
	}
	return newAct, nil
}

// cancelActivities cancel activities
// If this activity is already cancelled, set activity rank to 0
// So after this function, the activity rank will be correct for update user rank
func (vr *VoteRepo) cancelActivities(session *xorm.Session, activities []*entity.Activity) (err error) {
	for _, activity := range activities {
		t := &entity.Activity{}
		exist, err := session.ID(activity.ID).Get(t)
		if err != nil {
			log.Error(err)
			return err
		}
		if !exist {
			log.Error(fmt.Errorf("%s activity not exist", activity.ID))
			return fmt.Errorf("%s activity not exist", activity.ID)
		}
		//  If this activity is already cancelled, set activity rank to 0
		if t.Cancelled == entity.ActivityCancelled {
			activity.Rank = 0
		}
		if _, err = session.ID(activity.ID).Cols("cancelled", "cancelled_at").
			Update(&entity.Activity{
				Cancelled:   entity.ActivityCancelled,
				CancelledAt: time.Now(),
			}); err != nil {
			log.Error(err)
			return err
		}
	}
	return nil
}

func (vr *VoteRepo) getExistActivity(ctx context.Context, op *schema.VoteOperationInfo) ([]*entity.Activity, error) {

View on GitHub (pinned to 3b9f137061)

Solutions

  1. Confirm the activity ID exists: SELECT id FROM activities WHERE id = <id>;
  2. Make the caller check existence (or treat missing as already-cancelled) before invoking cancel.
  3. Remove stale references in the UI/API payloads; refresh the activity list.
  4. If soft-deletes are used, ensure the query isn't filtering out cancelled/deleted rows unintentionally.

Example fix

// before
if !exist {
    log.Error(fmt.Errorf("%s activity not exist", activity.ID))
    return fmt.Errorf("%s activity not exist", activity.ID)
}
// after
if !exist {
    log.Warnf("cancel skipped, activity %s not exist", activity.ID)
    return nil // or ErrActivityNotFound for the caller to handle idempotently
}
Defensive patterns

Strategy: try-catch

Validate before calling

var act entity.Activity
exist, err := db.ID(activityID).Get(&act)
if err == nil && !exist {
    // treat as already-cancelled / report not found to the UI before calling cancel
    return fmt.Errorf("activity %d not found, cannot cancel", activityID)
}

Type guard

func activityExists(rows []entity.Activity, id int64) bool {
    for _, a := range rows {
        if a.ID == id {
            return true
        }
    }
    return false
}

Try / catch

err := activityService.CancelActivities(ctx, ids)
if err != nil {
    if strings.Contains(err.Error(), "activity not exist") {
        // idempotent: already gone, refresh list
        return nil
    }
    return err
}

Prevention

When it happens

Trigger: Calling cancelActivities with an activity.ID that is not in the activities table (already hard-deleted, wrong ID, or from a different database).

Common situations: Double-clicking a cancel action after the activity was already removed; stale admin UI listing deleted activities; importing IDs across environments.

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/68cae57a781b6cbf. Report an issue: GitHub.