crowdsecurity/crowdsec · error · QueryFail

pagination size: %d, offset: %d: %w: %w

Error message

pagination size: %d, offset: %d: %w: %w

What it means

The paginated fetch (Limit/Offset All query) failed while walking alerts page by page. The message includes pagination size and offset plus both the underlying error and the QueryFail sentinel, double-wrapped with %w.

Source

Thrown at pkg/database/alerts.go:859

			WithMetas().
			WithOwner()

		if limit == 0 {
			limit, err = alerts.Count(ctx)
			if err != nil {
				return nil, fmt.Errorf("unable to count nb alerts: %w", err)
			}
		}

		if sort == "ASC" {
			alerts = alerts.Order(ent.Asc(alert.FieldCreatedAt), ent.Asc(alert.FieldID))
		} else {
			alerts = alerts.Order(ent.Desc(alert.FieldCreatedAt), ent.Desc(alert.FieldID))
		}

		result, err := alerts.Limit(paginationSize).Offset(offset).All(ctx)
		if err != nil {
			return nil, fmt.Errorf("pagination size: %d, offset: %d: %w: %w", paginationSize, offset, err, QueryFail)
		}

		if len(result) == 0 { // no results, no need to try to paginate further
			c.Log.Debugf("Pagination done because no results found at offset %d | len(ret) %d", offset, len(ret))
			break
		}

		log.Debugf("QueryAlertWithFilter: pagination size %d, offset %d, got %d results", paginationSize, offset, len(result))
		log.Debugf("diff is %d, limit is %d", limit-len(ret), limit)

		if diff := limit - len(ret); diff < paginationSize {
			if len(result) < diff {
				ret = append(ret, result...)
				c.Log.Debugf("Pagination done, %d < %d", len(result), diff)

				break
			}

View on GitHub (pinned to 909b515798)

Solutions

  1. Read the first wrapped error in the chain for the true cause (errors.Unwrap twice)
  2. Retry with a smaller paginationSize or explicit limit
  3. Increase the context timeout for large exports (cscli alerts list)
  4. Check DB stability across the whole pagination loop
Defensive patterns

Strategy: try-catch

Try / catch

_, err := client.FindAlerts(ctx, filter)
if err != nil {
    var qf interface{ Unwrap() error }
    // double-wrapped: inspect both wrapped errors
    return fmt.Errorf("alert listing failed: %w", err)
}

Prevention

When it happens

Trigger: alerts.Limit(paginationSize).Offset(offset).All(ctx) fails at some page during the loop — DB disconnect mid-pagination, context cancellation, or driver error.

Common situations: Long pagination loops over large alert tables outliving DB connection lifetime; context deadline exceeded while iterating; SQLite locking from a concurrent writer.

Understand the failure class

Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/f58fa403a27c5e3b. Report an issue: GitHub.