crowdsecurity/crowdsec · error

insert/update config item: %w

Error message

insert/update config item: %w

What it means

SetConfigItem wraps a failed upsert into config_items (INSERT ... ON CONFLICT UPDATE via ent OnConflictColumns). Any driver error while persisting key/value is wrapped with this message. Called by Pull, updateBlocklist, SaveAPICToken.

Source

Thrown at pkg/database/config.go:33

	case ent.IsNotFound(err):
		return "", nil
	case err != nil:
		return "", fmt.Errorf("select config item: %w: %w", err, QueryFail)
	default:
		return result.Value, nil
	}
}

func (c *Client) SetConfigItem(ctx context.Context, key string, value string) error {
	err := c.Ent.ConfigItem.
		Create().
		SetName(key).
		SetValue(value).
		OnConflictColumns(configitem.FieldName).
		UpdateNewValues().
		Exec(ctx)
	if err != nil {
		return fmt.Errorf("insert/update config item: %w", err)
	}

	return nil
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Check for SQLite lock contention (WAL mode, single writer) or disk-full conditions
  2. Inspect the wrapped driver error for constraint/schema causes
  3. Verify the database schema is current (re-run migrations/restart)
  4. Retry transient failures for remote databases
Defensive patterns

Strategy: retry

Validate before calling

if key == "" || value == "" { return errors.New("config item key/value must not be empty") }

Try / catch

if err := c.SetConfigItem(ctx, key, val); err != nil {
	if errors.Is(errors.Unwrap(err), sqlite.ErrLocked) { retryWithBackoff() }
	return fmt.Errorf("persisting %s failed: %w", key, err)
}

Prevention

When it happens

Trigger: Database locked or unavailable during the upsert, constraint violation on the name column, schema mismatch, or context cancellation.

Common situations: 'database is locked' when crowdsec and LAPI write simultaneously to SQLite; disk full preventing the write; corrupted DB after an upgrade.

Related errors


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