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
- Check for SQLite lock contention (WAL mode, single writer) or disk-full conditions
- Inspect the wrapped driver error for constraint/schema causes
- Verify the database schema is current (re-run migrations/restart)
- 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
- Serialize writers or enable WAL mode on SQLite
- Monitor free disk space
- Run migrations before writes after upgrades
- Retry idempotent upserts — they're safe to repeat
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
- select config item: %w: %w
- no database configuration provided
- max_items can't be zero or negative
- while getting allowlist %s: %s
- while getting alert: %w
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/b88a7fa869e6ad7e.
Report an issue: GitHub.