{"record":{"id":"b88a7fa869e6ad7e","repo":"crowdsecurity/crowdsec","slug":"insert-update-config-item-w","errorCode":null,"errorMessage":"insert/update config item: %w","messagePattern":"insert/update config item: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/database/config.go","lineNumber":33,"sourceCode":"\tcase ent.IsNotFound(err):\n\t\treturn \"\", nil\n\tcase err != nil:\n\t\treturn \"\", fmt.Errorf(\"select config item: %w: %w\", err, QueryFail)\n\tdefault:\n\t\treturn result.Value, nil\n\t}\n}\n\nfunc (c *Client) SetConfigItem(ctx context.Context, key string, value string) error {\n\terr := c.Ent.ConfigItem.\n\t\tCreate().\n\t\tSetName(key).\n\t\tSetValue(value).\n\t\tOnConflictColumns(configitem.FieldName).\n\t\tUpdateNewValues().\n\t\tExec(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"insert/update config item: %w\", err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":15,"sourceCodeEnd":38,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/config.go#L15-L38","documentation":"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.","triggerScenarios":"Database locked or unavailable during the upsert, constraint violation on the name column, schema mismatch, or context cancellation.","commonSituations":"'database is locked' when crowdsec and LAPI write simultaneously to SQLite; disk full preventing the write; corrupted DB after an upgrade.","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"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if key == \"\" || value == \"\" { return errors.New(\"config item key/value must not be empty\") }","typeGuard":null,"tryCatchPattern":"if err := c.SetConfigItem(ctx, key, val); err != nil {\n\tif errors.Is(errors.Unwrap(err), sqlite.ErrLocked) { retryWithBackoff() }\n\treturn fmt.Errorf(\"persisting %s failed: %w\", key, err)\n}","preventionTips":["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"],"tags":["database","ent","config","upsert"],"backgroundTag":"database-write-failed","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}