{"record":{"id":"82184d5e995d08b9","repo":"grafana/k6","slug":"closing-multipart-form-writer-w","errorCode":null,"errorMessage":"closing multipart form writer: %w","messagePattern":"closing multipart form writer: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/storage/file_persister.go","lineNumber":229,"sourceCode":"\t// copy all form fields received from a presigned URL\n\t// response to the multipart form fields.\n\tvar form bytes.Buffer\n\tfw := multipart.NewWriter(&form)\n\tfor k, v := range psu.FormFields {\n\t\tif err := fw.WriteField(k, v); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"writing form field key %q and value %q: %w\", k, v, err)\n\t\t}\n\t}\n\t// attach the file data to the form.\n\tff, err := fw.CreateFormFile(\"file\", psu.Name)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"creating multipart form file: %w\", err)\n\t}\n\tif _, err := io.Copy(ff, data); err != nil {\n\t\treturn nil, fmt.Errorf(\"copying file data to multipart form: %w\", err)\n\t}\n\tif err := fw.Close(); err != nil {\n\t\treturn nil, fmt.Errorf(\"closing multipart form writer: %w\", err)\n\t}\n\n\treq, err := http.NewRequestWithContext(\n\t\tctx,\n\t\tpsu.Method,\n\t\tpsu.PresignedURL,\n\t\t&form,\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"creating new request: %w\", err)\n\t}\n\treq.Header.Set(\"Content-Type\", fw.FormDataContentType())\n\n\treturn req, nil\n}\n\nfunc checkStatusCode(resp *http.Response) error {\n\tif resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/storage/file_persister.go#L211-L247","documentation":"Raised in newFileUploadRequest when multipart.Writer.Close fails after all fields and the file part were written. Close writes the final multipart boundary; failure is a buffer-level write error (e.g. allocation failure or an already-corrupted writer state). It means the assembled form body is incomplete and the upload request cannot be finalized.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/storage/file_persister.go:229 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the persist; transient buffer write failures are rare but recoverable","Check process memory if form assembly failures recur with large artifacts","Report as a bug if reproducible with specific artifact sizes"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}