{"record":{"id":"75fa2459cc7f23b9","repo":"Tencent/WeKnora","slug":"write-file-content-w","errorCode":null,"errorMessage":"write file content: %w","messagePattern":"write file content: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/docparser/mineru_converter.go","lineNumber":232,"sourceCode":"\tif c.language != \"\" {\n\t\tfields[\"lang_list\"] = c.language\n\t}\n\tif c.vlmServerURL != \"\" && (strings.HasPrefix(c.backend, \"vlm-http-client\") || strings.HasPrefix(c.backend, \"hybrid-http-client\")) {\n\t\tfields[\"server_url\"] = c.vlmServerURL\n\t}\n\tfor k, v := range fields {\n\t\t_ = writer.WriteField(k, v)\n\t}\n\n\tuploadFileName := minerUUploadFileName(fileName, fileType)\n\n\t// File part\n\tpart, err := writer.CreateFormFile(\"files\", uploadFileName)\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"create form file: %w\", err)\n\t}\n\tif _, err := part.Write(content); err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"write file content: %w\", err)\n\t}\n\twriter.Close()\n\n\thttpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, c.endpoint+\"/file_parse\", &body)\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"create request: %w\", err)\n\t}\n\thttpReq.Header.Set(\"Content-Type\", writer.FormDataContentType())\n\n\tclient := utils.NewSSRFSafeHTTPClient(utils.SSRFSafeHTTPClientConfig{\n\t\tTimeout:      mineruTimeout,\n\t\tMaxRedirects: 5,\n\t})\n\tresp, err := client.Do(httpReq)\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"HTTP request: %w\", err)\n\t}\n\tdefer resp.Body.Close()","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/docparser/mineru_converter.go#L214-L250","documentation":"Writing the uploaded document's bytes into the multipart field failed (part.Write(content)). This surfaces when the in-memory pipe/buffer backing the multipart writer fails, e.g. because the request body writer errored or memory allocation failed for very large files.","triggerScenarios":"part.Write(content) returns n < len(content) with a non-nil error while callFileParse assembles the form for the /file_parse request.","commonSituations":"Extremely large documents exhausting memory (body is an in-memory buffer); a custom body writer (bytes.Buffer/pipe) closed prematurely; OOM pressure on the host causing allocation failures.","solutions":["Check the document size against reasonable limits before calling Read (reject/limit huge files earlier in the pipeline).","Confirm the multipart writer and its backing buffer are used correctly (no early Close, single goroutine).","Inspect host memory (OOM logs, dmesg) if this occurs with large PDFs.","Check that content passed into Read is fully valid (not a zero-length/corrupt slice from an earlier failed read)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if len(content) == 0 {\n    return fmt.Errorf(\"refusing to send empty document to MinerU\")\n}\nif maxDocSize > 0 && len(content) > maxDocSize {\n    return fmt.Errorf(\"document too large for MinerU: %d bytes\", len(content))\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"write file content\") {\n    // in-memory failure: reject the document rather than retry\n    return fmt.Errorf(\"document rejected (write failed): %w\", err)\n}","preventionTips":["Enforce a maximum document size before calling the converter","Monitor host memory; streaming large files instead of buffering if needed","Ensure content is fully read and valid before passing to Read","Keep single-writer usage of the multipart writer (no concurrent writes)"],"tags":["multipart","io","memory","mineru"],"backgroundTag":"request-body-write-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}