crowdsecurity/crowdsec · error

nil alert

Error message

nil alert

What it means

Generic guard in UpdateCommunityBlocklist: the function requires a non-nil *models.Alert to insert into the database; a nil alert pointer was passed by SaveAlerts, indicating a programming error upstream, so it fails fast instead of panicking.

Source

Thrown at pkg/database/alerts.go:195

		if err != nil {
			return fmt.Errorf("creating alert decisions: %w", err)
		}
		decisions = append(decisions, ret...)
		return nil
	}); err != nil {
		return "", err
	}

	return "", nil
}

// UpdateCommunityBlocklist is called to update either the community blocklist (or other lists the user subscribed to)
// it takes care of creating the new alert with the associated decisions, and it will as well deleted the "older" overlapping decisions:
// 1st pull, you get decisions [1,2,3]. it inserts [1,2,3]
// 2nd pull, you get decisions [1,2,3,4]. it inserts [1,2,3,4] and will try to delete [1,2,3,4] with a different alert ID and same origin
func (c *Client) UpdateCommunityBlocklist(ctx context.Context, alertItem *models.Alert) (int, int, int, error) {
	if alertItem == nil {
		return 0, 0, 0, errors.New("nil alert")
	}

	if alertItem.StartAt == nil {
		return 0, 0, 0, errors.New("nil start_at")
	}

	startAtTime, err := time.Parse(time.RFC3339, *alertItem.StartAt)
	if err != nil {
		return 0, 0, 0, fmt.Errorf("start_at field time '%s': %w: %w", *alertItem.StartAt, err, ParseTimeFail)
	}

	if alertItem.StopAt == nil {
		return 0, 0, 0, errors.New("nil stop_at")
	}

	stopAtTime, err := time.Parse(time.RFC3339, *alertItem.StopAt)
	if err != nil {
		return 0, 0, 0, fmt.Errorf("stop_at field time '%s': %w: %w", *alertItem.StopAt, err, ParseTimeFail)

View on GitHub (pinned to 909b515798)

Solutions

  1. Fix the caller to pass a non-nil alert item
  2. Add a nil check before constructing the blocklist update in tests or wrappers
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at pkg/database/alerts.go:195 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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