{"record":{"id":"899ae7f8d9601b89","repo":"crowdsecurity/crowdsec","slug":"unable-to-serialize","errorCode":null,"errorMessage":"unable to serialize","messagePattern":"unable to serialize","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/database/errors.go","lineNumber":16,"sourceCode":"package database\n\nimport \"errors\"\n\nvar (\n\tUserExists        = errors.New(\"user already exist\")\n\tUserNotExists     = errors.New(\"user doesn't exist\")\n\tHashError         = errors.New(\"unable to hash\")\n\tInsertFail        = errors.New(\"unable to insert row\")\n\tQueryFail         = errors.New(\"unable to query\")\n\tUpdateFail        = errors.New(\"unable to update\")\n\tDeleteFail        = errors.New(\"unable to delete\")\n\tItemNotFound      = errors.New(\"object not found\")\n\tParseTimeFail     = errors.New(\"unable to parse time\")\n\tParseDurationFail = errors.New(\"unable to parse duration\")\n\tMarshalFail       = errors.New(\"unable to serialize\")\n\tBulkError         = errors.New(\"unable to insert bulk\")\n\tParseType         = errors.New(\"unable to parse type\")\n\tInvalidIPOrRange  = errors.New(\"invalid ip address / range\")\n\tInvalidFilter     = errors.New(\"invalid filter\")\n)\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/errors.go#L1-L22","documentation":"MarshalFail is a sentinel error meaning JSON serialization of event metadata failed. buildEventCreates marshals each event's Meta map to store it in the events table; any value in the map that json.Marshal cannot serialize (channels, funcs, invalid nested types) triggers it.","triggerScenarios":"CreateAlert/buildEventCreates when an event's Meta contains non-JSON-serializable values or cyclic structures, e.g. a custom parser stuffing odd types into event.Meta.","commonSituations":"Parsers producing meta values of exotic Go types (float NaN is fine, but funcs/channels are not), plugins or post-parsers injecting non-primitive values, custom forked code altering Meta types.","solutions":["Ensure Meta values are JSON-primitives (string, number, bool, nil) or composites of them.","Inspect the wrapped inner error, which names the offending value: json: unsupported type: ...","Sanitize Meta in the parser: convert unknown values with fmt.Sprintf(\"%v\", v) before adding.","If forking, avoid storing Go-native objects in Meta; keep it a map[string]string."],"exampleFix":"// before\nmeta := models.Meta{\"raw\": someFuncValue}\n// after\nmeta := models.Meta{\"raw\": fmt.Sprintf(\"%v\", someValue)}","handlingStrategy":"validation","validationCode":"// Go: ensure Meta values are JSON-encodable before ingestion\nfunc jsonSafe(meta models.Meta) error {\n    _, err := json.Marshal(meta)\n    return err\n}","typeGuard":null,"tryCatchPattern":"if _, err := client.CreateAlert(ctx, alert); err != nil {\n    if errors.Is(err, database.MarshalFail) {\n        log.Errorf(\"non-serializable meta: %v\", err)\n        return sanitizeMetaAndRetry(alert)\n    }\n    return err\n}","preventionTips":["Keep event Meta values as JSON primitives only","Never inject Go-native objects (funcs, channels) into Meta","Pre-marshal Meta in tests for custom parsers"],"tags":["database","crowdsec","json","serialization"],"backgroundTag":"json-serialization-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"}