{"record":{"id":"0bc9d506e225f458","repo":"weaviate/weaviate","slug":"marshal-request-w-0bc9d5","errorCode":null,"errorMessage":"marshal request: %w","messagePattern":"marshal request: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"cluster/raft_apply_endpoints.go","lineNumber":40,"sourceCode":"\t\"github.com/prometheus/client_golang/prometheus\"\n\tcmd \"github.com/weaviate/weaviate/cluster/proto/api\"\n\t\"github.com/weaviate/weaviate/cluster/schema\"\n\t\"github.com/weaviate/weaviate/cluster/types\"\n\t\"github.com/weaviate/weaviate/entities/models\"\n\t\"github.com/weaviate/weaviate/usecases/monitoring\"\n\t\"github.com/weaviate/weaviate/usecases/sharding\"\n\t\"google.golang.org/protobuf/proto\"\n)\n\nfunc (s *Raft) AddClass(ctx context.Context, cls *models.Class, ss *sharding.State) (uint64, error) {\n\tif cls == nil || cls.Class == \"\" {\n\t\treturn 0, fmt.Errorf(\"nil class or empty class name: %w\", schema.ErrBadRequest)\n\t}\n\n\treq := cmd.AddClassRequest{Class: cls, State: ss}\n\tsubCommand, err := json.Marshal(&req)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"marshal request: %w\", err)\n\t}\n\tcommand := &cmd.ApplyRequest{\n\t\tType:       cmd.ApplyRequest_TYPE_ADD_CLASS,\n\t\tClass:      cls.Class,\n\t\tSubCommand: subCommand,\n\t}\n\treturn s.Execute(ctx, command)\n}\n\nfunc (s *Raft) UpdateClass(ctx context.Context, cls *models.Class, _ *sharding.State) (uint64, error) {\n\tif cls == nil || cls.Class == \"\" {\n\t\treturn 0, fmt.Errorf(\"nil class or empty class name: %w\", schema.ErrBadRequest)\n\t}\n\n\treq := cmd.UpdateClassRequest{Class: cls}\n\tsubCommand, err := json.Marshal(&req)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"marshal request: %w\", err)","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/cluster/raft_apply_endpoints.go#L22-L58","documentation":"After validation, AddClass serializes cmd.AddClassRequest (class plus sharding state) with json.Marshal to use as the SubCommand of an ApplyRequest. This error wraps a marshal failure that aborts the write before it reaches RAFT. As the struct holds only JSON-safe types, hitting this in a stock build points to non-serializable data injected into the request (custom code, cyclic references in sharding state, or a patched struct).","triggerScenarios":"Calling AddClass when json.Marshal of cmd.AddClassRequest fails — non-JSON-serializable values (chan/func/cycle) inside the models.Class (e.g. in custom invectors/module config) or the *sharding.State argument.","commonSituations":"A fork added a field with a func or channel to models.Class or sharding.State; a cyclic reference introduced via module-config pointers; corrupted build after partial code regeneration of the cmd package.","solutions":["Inspect the wrapped %w cause to see exactly what json.Marshal rejected.","Audit the models.Class payload and sharding state for chan, func, complex, or cyclic fields; remove them or mark them json:\"-\".","Verify custom module config passed in the class is plain JSON-serializable data.","Rebuild from a clean checkout; if reproducible on stock code, report upstream."],"exampleFix":"// before: cyclic pointer in class module config\ncfg.Inverter = cfg // cycle -> json.Marshal fails\n// after\nvar cfg ModuleConfig // keep config a plain JSON tree\nclass.ModuleConfig = cfg","handlingStrategy":"validation","validationCode":"if _, err := json.Marshal(cmd.AddClassRequest{Class: cls, State: ss}); err != nil {\n    return fmt.Errorf(\"class payload not serializable: %w\", err)\n}\n// then call AddClass","typeGuard":"func jsonSafe(v any) bool {\n    _, err := json.Marshal(v)\n    return err == nil\n}","tryCatchPattern":"err := schema.AddClass(ctx, cls, ss)\nif err != nil && strings.HasPrefix(err.Error(), \"marshal request\") {\n    logger.Errorf(\"AddClass payload unserializable: %v\", err)\n    return err\n}","preventionTips":["Keep models.Class and sharding.State free of chan/func/cyclic fields.","Treat module configs as plain JSON data only.","Add a unit test asserting AddClassRequest marshals for representative classes."],"tags":["raft","json","serialization","schema"],"backgroundTag":"json-marshal-failed","analyzedSha":"75aa4b6d11f8818305aafd4440b4e32794f7ca04","analyzedAt":"2026-09-04T14:58:20.392Z","contentChangedAt":"2026-09-04T14:58:20.392Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}