{"record":{"id":"2a8c42969305e2ff","repo":"crowdsecurity/crowdsec","slug":"machine-not-found","errorCode":null,"errorMessage":"machine not found","messagePattern":"machine not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/database/machines.go","lineNumber":146,"sourceCode":"}\n\nfunc (c *Client) ListMachines(ctx context.Context) ([]*ent.Machine, error) {\n\tmachines, err := c.Ent.Machine.Query().All(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"listing machines: %w: %w\", err, QueryFail)\n\t}\n\n\treturn machines, nil\n}\n\nfunc (c *Client) ValidateMachine(ctx context.Context, machineID string) error {\n\trets, err := c.Ent.Machine.Update().Where(machine.MachineIdEQ(machineID)).SetIsValidated(true).Save(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"validating machine: %w: %w\", err, UpdateFail)\n\t}\n\n\tif rets == 0 {\n\t\treturn errors.New(\"machine not found\")\n\t}\n\n\treturn nil\n}\n\nfunc (c *Client) QueryPendingMachine(ctx context.Context) ([]*ent.Machine, error) {\n\tmachines, err := c.Ent.Machine.Query().Where(machine.IsValidatedEQ(false)).All(ctx)\n\tif err != nil {\n\t\tc.Log.Warningf(\"QueryPendingMachine : %s\", err)\n\t\treturn nil, fmt.Errorf(\"querying pending machines: %w: %w\", err, QueryFail)\n\t}\n\n\treturn machines, nil\n}\n\nfunc (c *Client) DeleteWatcher(ctx context.Context, name string) error {\n\tnbDeleted, err := c.Ent.Machine.\n\t\tDelete().","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/machines.go#L128-L164","documentation":"ValidateMachine marks an alert-parsing/decision machine as validated in the local DB. It first runs an ent update filtered by machine_id; if the update succeeds but affects 0 rows, no machine with that ID exists, so it returns 'machine not found'. Note the earlier branch wraps DB errors in UpdateFail, this one is purely a zero-rows condition.","triggerScenarios":"Calling ValidateMachine(ctx, machineID) with a machine_id that has no row in the machines table, e.g. via LAPI /machines/validate with a wrong or stale machine name.","commonSituations":"Bouncer/enrollment API called with a machine identifier that was deleted, typo in machine name, validating on the wrong LAPI instance, machine purged by db_flush.","solutions":["Query the machine list (cscli machines list or LAPI) and use an exact existing machine_id","Check for typos/case in the machine identifier","Re-register the machine with cscli if it was deleted"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"machines, err := client.QueryMachine(ctx, machineID)\nif err != nil || len(machines) == 0 {\n    return fmt.Errorf(\"machine %q does not exist\", machineID)\n}\n_ = client.ValidateMachine(ctx, machineID)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["List machines first and validate by exact machine_id from the listing","Handle 404-style empties from LAPI validate endpoints gracefully","Watch for machines purged by flush retention policies"],"tags":["database","crowdsec","lapi"],"backgroundTag":"entity-not-found","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"}