crowdsecurity/crowdsec · error · UpdateFail
validating machine: %w: %w
Error message
validating machine: %w: %w
What it means
ValidateMachine wraps the UpdateFail sentinel when the bulk `Machine.Update().Where(...).SetIsValidated(true).Save(ctx)` fails. Separately, if the update succeeds but touches 0 rows, a plain error 'machine not found' is returned. So this specific error is a DB write failure while validating a watcher, not a missing machine.
Source
Thrown at pkg/database/machines.go:142
return &ent.Machine{}, fmt.Errorf("user '%s': %w", machineID, UserNotExists)
}
return machine, nil
}
func (c *Client) ListMachines(ctx context.Context) ([]*ent.Machine, error) {
machines, err := c.Ent.Machine.Query().All(ctx)
if err != nil {
return nil, fmt.Errorf("listing machines: %w: %w", err, QueryFail)
}
return machines, nil
}
func (c *Client) ValidateMachine(ctx context.Context, machineID string) error {
rets, err := c.Ent.Machine.Update().Where(machine.MachineIdEQ(machineID)).SetIsValidated(true).Save(ctx)
if err != nil {
return fmt.Errorf("validating machine: %w: %w", err, UpdateFail)
}
if rets == 0 {
return errors.New("machine not found")
}
return nil
}
func (c *Client) QueryPendingMachine(ctx context.Context) ([]*ent.Machine, error) {
machines, err := c.Ent.Machine.Query().Where(machine.IsValidatedEQ(false)).All(ctx)
if err != nil {
c.Log.Warningf("QueryPendingMachine : %s", err)
return nil, fmt.Errorf("querying pending machines: %w: %w", err, QueryFail)
}
return machines, nil
}View on GitHub (pinned to 909b515798)
Solutions
- Read the wrapped error for the SQL-level cause
- Retry the validation once the DB is writable: `cscli machines validate <name>`
- Check for competing processes locking the SQLite DB (backup jobs, second LAPI)
- Verify schema version matches: `cscli migration`
- Confirm the machine exists first via `cscli machines list` to distinguish from 'machine not found'
Defensive patterns
Strategy: try-catch
Validate before calling
// verify the machine exists before validating
rets, _ := db.QueryMachineByID(ctx, machineID)
if rets == nil || rets.ID == 0 {
return fmt.Errorf("machine %q not found", machineID)
} Try / catch
if err := db.ValidateMachine(ctx, machineID); err != nil {
if err.Error() == "machine not found" {
// distinct case: unknown id
} else if errors.Is(err, database.UpdateFail) {
// DB write failure: inspect cause, retry
}
return err
} Prevention
- Validate only machines listed by `cscli machines list`
- Serialize DB writers or move to a client/server DB to avoid SQLite lock errors
- Keep free disk headroom on the DB volume
- Run schema migrations immediately after binary upgrades
When it happens
Trigger: Calling ValidateMachine (LAPI 'validate' controller, `cscli machines validate <name>`) with the DB refusing the UPDATE: connection lost, SQLite locked by another process, schema mismatch on the machines table.
Common situations: Concurrent LAPI writers holding the SQLite write lock; disk full preventing the update; schema drift after partial upgrade; remote DB credentials rotated.
Related errors
- machine not found
- get all decisions with filters: %w
- latest decision id: %w
- get expired decisions with filters: %w
- query decision failed: %w
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/c7cc7ae71d16ba5b.
Report an issue: GitHub.