{"record":{"id":"f4e4f08d0d664f5d","repo":"weaviate/weaviate","slug":"marshal-body-f4e4f0","errorCode":null,"errorMessage":"marshal body","messagePattern":"marshal body","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"modules/text2vec-ollama/clients/ollama.go","lineNumber":71,"sourceCode":"\treturn res, nil, 0, err\n}\n\nfunc (v *ollama) VectorizeQuery(ctx context.Context, input []string,\n\tcfg moduletools.ClassConfig,\n) (*modulecomponents.VectorizationResult[[]float32], error) {\n\treturn v.vectorize(ctx, input, cfg)\n}\n\nfunc (v *ollama) vectorize(ctx context.Context, input []string,\n\tcfg moduletools.ClassConfig,\n) (*modulecomponents.VectorizationResult[[]float32], error) {\n\tsettings := ent.NewClassSettings(cfg)\n\tbody, err := json.Marshal(embeddingsRequest{\n\t\tModel: settings.Model(),\n\t\tInput: input,\n\t})\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"marshal body\")\n\t}\n\n\tendpointURL := v.urlBuilderFn(settings.ApiEndpoint())\n\n\treq, err := http.NewRequestWithContext(ctx, \"POST\", endpointURL,\n\t\tbytes.NewReader(body))\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"create POST request\")\n\t}\n\n\tres, err := v.httpClient.Do(req)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"send POST request\")\n\t}\n\tdefer res.Body.Close()\n\n\tbodyBytes, err := io.ReadAll(res.Body)\n\tif err != nil {","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/modules/text2vec-ollama/clients/ollama.go#L53-L89","documentation":"The text2vec-ollama client serializes the embeddings request ({model, input}) with json.Marshal before POSTing to <endpoint>/api/embed and wraps any failure as \"marshal body\". marshaling a struct of a string and []string cannot realistically fail (only channels/funcs/cycles fail), so this error almost never occurs; if you do see it, it points to modified request structs or a corrupted build rather than anything about your Ollama setup. Note the variable shadowing: the marshaled JSON is also called \"body\", but this error is not about the HTTP response body.","triggerScenarios":"Calling Vectorize (object indexing) or VectorizeQuery (nearText/nearVector search) against the Ollama module and json.Marshal of embeddingsRequest returns an error — only possible if the request struct gains unmarshalable fields (chan/func/cyclic) in a modified build.","commonSituations":"Essentially only in custom forks of modules/text2vec-ollama/clients/ollama.go; users who see errors at this call site are usually actually hitting the later \"send POST request\" (Ollama unreachable) or \"connection to Ollama API failed\" errors.","solutions":["Read the underlying error after \"marshal body: \" — json.Marshal errors name the offending field type.","Confirm you run unmodified text2vec-ollama client code; the stock embeddingsRequest (Model string, Input []string) cannot fail to marshal.","If you extended embeddingsRequest, remove or make marshalable the unmarshalable field (e.g. marshal a separate DTO).","If the real problem is connecting to Ollama, check OLLAMA_HOST/endpoint config — that failure surfaces as \"send POST request\", not \"marshal body\"."],"exampleFix":"// before: unmarshalable field added to request\ntype embeddingsRequest struct {\n  Model string `json:\"model\"`\n  Input []string `json:\"input\"`\n  OnDone func() `json:\"-\"` // chan/func fields break json.Marshal\n}\n// after: keep the wire DTO plain\ntype embeddingsRequest struct {\n  Model string `json:\"model\"`\n  Input []string `json:\"input\"`\n}","handlingStrategy":"try-catch","validationCode":"// Go: validate inputs before vectorizing with text2vec-ollama\nfunc validOllamaVectorizeInput(input []string, model, endpoint string) error {\n  if len(input) == 0 { return errors.New(\"input must not be empty\") }\n  if model == \"\" { return errors.New(\"moduleConfig requires a model, e.g. 'nomic-embed-text'\") }\n  if endpoint == \"\" { return errors.New(\"ollama endpoint (e.g. http://ollama:11434) is required\") }\n  return nil\n}","typeGuard":null,"tryCatchPattern":"// Go: classify batch errors at the call site\nvecs, errs := vectorizer.VectorizeBatch(ctx, objs, skip, cfg)\nfor i, err := range errs {\n  var orig error\n  if errors.As(err, &orig) && strings.Contains(err.Error(), \"marshal body\") {\n    log.Errorf(\"object %d: request serialization bug (report/fork issue): %v\", i, err)\n  } else {\n    log.Errorf(\"object %d: vectorization failed: %v\", i, err) // retryable transport/API errors\n  }\n}","preventionTips":["Keep the request struct free of chan/func/map-with-cycle fields if you fork the client.","Validate moduleConfig (model, apiEndpoint) before creating/patching a class so failures happen at schema time.","Distinguish \"marshal body\" (serialization bug) from \"send POST request\" (Ollama unreachable) when reading logs.","Use error unwrapping (errors.As/Is) instead of string-matching the outer wrapper message."],"tags":["go","json","serialization","weaviate","ollama"],"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-23T08:17:48.524Z"}