{"record":{"id":"d5d063ba5d522881","repo":"crowdsecurity/crowdsec","slug":"unable-to-update","errorCode":null,"errorMessage":"unable to update","messagePattern":"unable to update","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/database/errors.go","lineNumber":11,"sourceCode":"package database\n\nimport \"errors\"\n\nvar (\n\tUserExists        = errors.New(\"user already exist\")\n\tUserNotExists     = errors.New(\"user doesn't exist\")\n\tHashError         = errors.New(\"unable to hash\")\n\tInsertFail        = errors.New(\"unable to insert row\")\n\tQueryFail         = errors.New(\"unable to query\")\n\tUpdateFail        = errors.New(\"unable to update\")\n\tDeleteFail        = errors.New(\"unable to delete\")\n\tItemNotFound      = errors.New(\"object not found\")\n\tParseTimeFail     = errors.New(\"unable to parse time\")\n\tParseDurationFail = errors.New(\"unable to parse duration\")\n\tMarshalFail       = errors.New(\"unable to serialize\")\n\tBulkError         = errors.New(\"unable to insert bulk\")\n\tParseType         = errors.New(\"unable to parse type\")\n\tInvalidIPOrRange  = errors.New(\"invalid ip address / range\")\n\tInvalidFilter     = errors.New(\"invalid filter\")\n)\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/errors.go#L1-L22","documentation":"UpdateFail is a sentinel error from crowdsec's database layer meaning an UPDATE/SAVE operation against the persistent store failed. It is wrapped around the underlying ent ORM error (or returned alone) whenever a machine record cannot be created/validated/updated, so callers can match it with errors.Is while the root cause stays wrapped.","triggerScenarios":"CreateMachine when machine.MachineIdEQ(...).Save(ctx) fails (e.g. duplicate machine_id unique constraint, DB connection lost); ValidateMachine when SetIsValidated(true).Save fails; UpdateMachineLastHeartBeat when the heartbeat update fails.","commonSituations":"Registering a machine whose ID already exists in the DB (duplicate cscli machine add), transient database outage or connection pool exhaustion during machine validation, migration/schema mismatch between the binary and the DB.","solutions":["Check the wrapped inner error in the log line (CreateMachine : %s) for the root cause (constraint, connectivity).","Verify database connectivity and credentials in crowdsec's db_config.","If registering a duplicate machine, delete or reuse the existing entry (cscli machines list / machines delete) before re-adding.","Run cscli with a migrated schema (cscli machines/migrations current) to rule out schema drift."],"exampleFix":"// before\nm, err := client.CreateMachine(ctx, machineID)\n// err: machine 'xxx': unable to update\n// after\nexisting, _ := client.QueryMachineByID(ctx, *machineID)\nif existing != nil {\n    // reuse or delete existing machine before creating\n    return client.UpdateMachine(ctx, *machineID)\n}\nm, err := client.CreateMachine(ctx, machineID)","handlingStrategy":"try-catch","validationCode":"// Go: check DB reachability and duplicate before creating\nif _, err := client.QueryMachineByID(ctx, *machineID); err == nil {\n    return fmt.Errorf(\"machine %s already exists\", *machineID)\n}\nif err := db.PingContext(ctx); err != nil {\n    return fmt.Errorf(\"db unavailable: %w\", err)\n}","typeGuard":"func isUpdateFail(err error) bool { return errors.Is(err, database.UpdateFail) }","tryCatchPattern":"if _, err := client.CreateMachine(ctx, machineID); err != nil {\n    if errors.Is(err, database.UpdateFail) {\n        log.Warnf(\"machine write failed (db issue?): %v\", err)\n        return retryLater\n    }\n    return err\n}","preventionTips":["Pre-check for duplicate machine IDs before registering","Monitor database connectivity; set reasonable timeouts in db_config","Keep schema migrated to the binary's version"],"tags":["database","crowdsec","update"],"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-14T00:17:10.932Z"}