crowdsecurity/crowdsec · error · UpdateFail
machine '%s': %w
Error message
machine '%s': %w
What it means
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.
Source
Thrown at pkg/database/machines.go:87
if err != nil {
c.Log.Warningf("CreateMachine: %s", err)
return nil, HashError
}
machineExist, err := c.Ent.Machine.
Query().
Where(machine.MachineIdEQ(*machineID)).
Select(machine.FieldMachineId).Strings(ctx)
if err != nil {
return nil, fmt.Errorf("machine '%s': %w: %w", *machineID, err, QueryFail)
}
if len(machineExist) > 0 {
if force {
_, err := c.Ent.Machine.Update().Where(machine.MachineIdEQ(*machineID)).SetPassword(string(hashPassword)).Save(ctx)
if err != nil {
c.Log.Warningf("CreateMachine : %s", err)
return nil, fmt.Errorf("machine '%s': %w", *machineID, UpdateFail)
}
machine, err := c.QueryMachineByID(ctx, *machineID)
if err != nil {
return nil, fmt.Errorf("machine '%s': %w: %w", *machineID, err, QueryFail)
}
return machine, nil
}
return nil, fmt.Errorf("user '%s': %w", *machineID, UserExists)
}
machine, err := c.Ent.Machine.
Create().
SetMachineId(*machineID).
SetPassword(string(hashPassword)).
SetIpAddress(ipAddress).View on GitHub (pinned to 909b515798)
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
Example fix
// before (fails opaquely) cscli machines add mymachine --force // after sqlite3 crowdsec.db "SELECT machine_id FROM machines WHERE machine_id='mymachine';" # verify row exists cscli machines add mymachine --force --password <newpass>
Defensive patterns
Strategy: try-catch
Validate before calling
exists, _ := client.Ent.Machine.Query().Where(machine.MachineIdEQ(id)).Exist(ctx) // row must exist for force update
Try / catch
if _, err := client.CreateMachine(ctx, &id, pass, ip, true, true, auth); err != nil {
if errors.Is(err, database.UpdateFail) {
// retry or delete-then-add
client.DeleteMachine(ctx, id)
client.CreateMachine(ctx, &id, pass, ip, true, false, auth)
}
} Prevention
- 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
When it happens
Trigger: `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.
Common situations: Force re-registering a machine whose row was just deleted by another admin; read replica used for writes; SQLite file locked.
Related errors
- machine %s attempted to auth with password but it is configu
- machine '%s': %w: %w
- no database configuration provided
- unable to update
- unable to delete
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/216b523703d413f0.
Report an issue: GitHub.