{"record":{"id":"216b523703d413f0","repo":"crowdsecurity/crowdsec","slug":"machine-s-w-216b52","errorCode":null,"errorMessage":"machine '%s': %w","messagePattern":"machine '(.+?)': %w","errorType":"exception","errorClass":"UpdateFail","httpStatus":null,"severity":"error","filePath":"pkg/database/machines.go","lineNumber":87,"sourceCode":"\tif err != nil {\n\t\tc.Log.Warningf(\"CreateMachine: %s\", err)\n\t\treturn nil, HashError\n\t}\n\n\tmachineExist, err := c.Ent.Machine.\n\t\tQuery().\n\t\tWhere(machine.MachineIdEQ(*machineID)).\n\t\tSelect(machine.FieldMachineId).Strings(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"machine '%s': %w: %w\", *machineID, err, QueryFail)\n\t}\n\n\tif len(machineExist) > 0 {\n\t\tif force {\n\t\t\t_, err := c.Ent.Machine.Update().Where(machine.MachineIdEQ(*machineID)).SetPassword(string(hashPassword)).Save(ctx)\n\t\t\tif err != nil {\n\t\t\t\tc.Log.Warningf(\"CreateMachine : %s\", err)\n\t\t\t\treturn nil, fmt.Errorf(\"machine '%s': %w\", *machineID, UpdateFail)\n\t\t\t}\n\n\t\t\tmachine, err := c.QueryMachineByID(ctx, *machineID)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"machine '%s': %w: %w\", *machineID, err, QueryFail)\n\t\t\t}\n\n\t\t\treturn machine, nil\n\t\t}\n\n\t\treturn nil, fmt.Errorf(\"user '%s': %w\", *machineID, UserExists)\n\t}\n\n\tmachine, err := c.Ent.Machine.\n\t\tCreate().\n\t\tSetMachineId(*machineID).\n\t\tSetPassword(string(hashPassword)).\n\t\tSetIpAddress(ipAddress).","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/machines.go#L69-L105","documentation":"When a machine already exists and `force` is set, CreateMachine updates its password; this error wraps an UpdateFail tag if that password update fails. The original driver error is only logged as a warning, not embedded.","triggerScenarios":"`cscli machines add --force` (or equivalent TLS re-registration) on an existing machineID whose password update `Machine.Update().SetPassword(...).Save(ctx)` fails — DB outage, machine row deleted concurrently, or a write constraint.","commonSituations":"Force re-registering a machine whose row was just deleted by another admin; read replica used for writes; SQLite file locked.","solutions":["Re-run `cscli machines add --force` after confirming DB is writable","Check that you are pointing at the primary DB, not a read-only replica","Delete and recreate the machine: `cscli machines delete <id>` then add again","Look for the preceding `CreateMachine : %s` warning log for the real driver error"],"exampleFix":"// before (fails opaquely)\ncscli machines add mymachine --force\n// after\nsqlite3 crowdsec.db \"SELECT machine_id FROM machines WHERE machine_id='mymachine';\"  # verify row exists\ncscli machines add mymachine --force --password <newpass>","handlingStrategy":"try-catch","validationCode":"exists, _ := client.Ent.Machine.Query().Where(machine.MachineIdEQ(id)).Exist(ctx) // row must exist for force update","typeGuard":null,"tryCatchPattern":"if _, err := client.CreateMachine(ctx, &id, pass, ip, true, true, auth); err != nil {\n    if errors.Is(err, database.UpdateFail) {\n        // retry or delete-then-add\n        client.DeleteMachine(ctx, id)\n        client.CreateMachine(ctx, &id, pass, ip, true, false, auth)\n    }\n}","preventionTips":["Check the preceding `CreateMachine : %s` warning for the real driver error","Ensure writes go to the primary DB, not a replica","Avoid concurrent force-add and delete of the same machine"],"tags":["database","machines","password"],"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"}