{"record":{"id":"b271e03072cd62a1","repo":"weaviate/weaviate","slug":"marshal-merge-document-w","errorCode":null,"errorMessage":"marshal merge document: %w","messagePattern":"marshal merge document: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"adapters/clients/replication_grpc.go","lineNumber":133,"sourceCode":"\t})\n\tif err != nil {\n\t\treturn replica.SimpleResponse{}, fmt.Errorf(\"gRPC PutObjects: %w\", err)\n\t}\n\n\treturn protoToSimpleResponse(resp.GetResponse()), nil\n}\n\nfunc (c *grpcReplicationClient) MergeObject(ctx context.Context, host, index, shard, requestID string,\n\tdoc *objects.MergeDocument, schemaVersion uint64,\n) (replica.SimpleResponse, error) {\n\tclient, err := c.getClient(host)\n\tif err != nil {\n\t\treturn replica.SimpleResponse{}, err\n\t}\n\n\tmergeData, err := json.Marshal(doc)\n\tif err != nil {\n\t\treturn replica.SimpleResponse{}, fmt.Errorf(\"marshal merge document: %w\", err)\n\t}\n\n\tctx, cancel := context.WithTimeout(ctx, COMMIT_TIMEOUT_VALUE*time.Second)\n\tdefer cancel()\n\n\tresp, err := client.MergeObject(ctx, &protocol.MergeObjectRequest{\n\t\tIndex:         index,\n\t\tShard:         shard,\n\t\tRequestId:     requestID,\n\t\tSchemaVersion: schemaVersion,\n\t\tMergeDocument: mergeData,\n\t})\n\tif err != nil {\n\t\treturn replica.SimpleResponse{}, fmt.Errorf(\"gRPC MergeObject: %w\", err)\n\t}\n\n\treturn protoToSimpleResponse(resp.GetResponse()), nil\n}","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/adapters/clients/replication_grpc.go#L115-L151","documentation":"This error wraps a json.Marshal failure on the *objects.MergeDocument before it is sent via the gRPC MergeObject replication RPC (adapters/clients/replication_grpc.go:133). JSON encoding of a merge document should rarely fail since it is mostly JSON-native types, so this usually indicates unsupported values embedded in the document. The write is aborted before any network traffic.","triggerScenarios":"Calling MergeObject with a MergeDocument containing values that encoding/json cannot serialize — e.g. channels, funcs, cyclic structures in custom property payloads, NaN/Inf floats in a struct marshaled via json (depending on codec), or an invalid underlying patch representation.","commonSituations":"Application inserting exotic property values through a programmatic client path; a module or custom extension injecting non-JSON-serializable data into the merge document; corruption in internally built merge patches.","solutions":["Read the wrapped error to identify the offending field/type.","Validate the MergeDocument's properties contain only JSON-serializable types before replication.","Reject unserializable values at the REST/gRPC API layer with a 400 instead of reaching replication.","If a module injects non-serializable values, fix the module's property conversion."],"exampleFix":"// before\nmergeData, err := json.Marshal(doc)\nif err != nil {\n    return replica.SimpleResponse{}, fmt.Errorf(\"marshal merge document: %w\", err)\n}\n// after\nmergeData, err := json.Marshal(doc)\nif err != nil {\n    return replica.SimpleResponse{}, usecases.NewErrInvalidUserInput(\"invalid merge document: %v\", err)\n}","handlingStrategy":"validation","validationCode":"func validateMergeDocumentSerializable(doc *objects.MergeDocument) error {\n    if doc == nil {\n        return errors.New(\"merge document is nil\")\n    }\n    // json.Marshal as a pre-flight check at the API layer\n    if _, err := json.Marshal(doc); err != nil {\n        return fmt.Errorf(\"merge document not JSON-serializable: %w\", err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"mergeData, err := json.Marshal(doc)\nif err != nil {\n    return replica.SimpleResponse{}, fmt.Errorf(\"marshal merge document: %w\", err)\n}","preventionTips":["Only put JSON-native types (string, number, bool, slices, maps) into merge document properties.","Reject non-serializable property values at the REST/gRPC API layer with a 400.","Keep module property converters producing plain JSON types."],"tags":["serialization","json","merge-patch","replication"],"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"}