{"record":{"id":"f99768a78659e6c5","repo":"crowdsecurity/crowdsec","slug":"alert-uuid-is-empty","errorCode":null,"errorMessage":"alert UUID is empty","messagePattern":"alert UUID is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/database/alerts.go","lineNumber":47,"sourceCode":"\tdefaultLimit        = 100 // default limit of element to returns when query alerts\n\talertCreateBulkSize = 50  // bulk size when create alerts\n\tmaxLockRetries      = 10  // how many times to retry a bulk operation when sqlite3.ErrBusy is encountered\n)\n\nfunc rollbackOnError(tx *ent.Tx, err error, msg string) error {\n\tif rbErr := tx.Rollback(); rbErr != nil {\n\t\tlog.Errorf(\"rollback error: %v\", rbErr)\n\t}\n\n\treturn fmt.Errorf(\"%s: %w\", msg, err)\n}\n\n// CreateOrUpdateAlert is specific to PAPI : It checks if alert already exists, otherwise inserts it\n// if alert already exists, it checks it associated decisions already exists\n// if some associated decisions are missing (ie. previous insert ended up in error) it inserts them\nfunc (c *Client) CreateOrUpdateAlert(ctx context.Context, machineID string, alertItem *models.Alert) (string, error) {\n\tif alertItem.UUID == \"\" {\n\t\treturn \"\", errors.New(\"alert UUID is empty\")\n\t}\n\n\talerts, err := c.Ent.Alert.Query().Where(alert.UUID(alertItem.UUID)).WithDecisions().All(ctx)\n\tif err != nil && !ent.IsNotFound(err) {\n\t\treturn \"\", fmt.Errorf(\"unable to query alerts for uuid %s: %w\", alertItem.UUID, err)\n\t}\n\n\t// alert wasn't found, insert it (expected hotpath)\n\tif ent.IsNotFound(err) || len(alerts) == 0 {\n\t\talertIDs, err := c.CreateAlert(ctx, machineID, []*models.Alert{alertItem})\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"unable to create alert: %w\", err)\n\t\t}\n\n\t\t// happy nilaway\n\t\tif len(alertIDs) == 0 {\n\t\t\treturn \"\", fmt.Errorf(\"unable to create alert: no IDs returned for alert %s\", alertItem.UUID)\n\t\t}","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/alerts.go#L29-L65","documentation":"Input guard in CreateOrUpdateAlert (PAPI path): the alert item carries an empty UUID, so it cannot be looked up or inserted. Means the upstream CAPI/PAPI payload did not populate the alert's UUID field.","triggerScenarios":"Thrown at pkg/database/alerts.go:47 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Regenerate or fix the PAPI payload so every alert has a UUID before calling CreateOrUpdateAlert","Check the deserialization of the PAPI response for a missing/misnamed UUID field"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}