{"record":{"id":"05477e6d335303f9","repo":"grafana/k6","slug":"writing-form-field-key-q-and-value-q-w","errorCode":null,"errorMessage":"writing form field key %q and value %q: %w","messagePattern":"writing form field key %q and value %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/storage/file_persister.go","lineNumber":217,"sourceCode":"}\n\n// newFileUploadRequest creates a new HTTP request to upload a file as a multipart\n// form to the presigned URL received from the server.\nfunc newFileUploadRequest(\n\tctx context.Context,\n\tresp PresignedURLResponse,\n\tdata io.Reader,\n) (*http.Request, error) {\n\t// we don't support multiple presigned URLs at the moment.\n\tpsu := resp.URLs[0]\n\n\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,","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/storage/file_persister.go#L199-L235","documentation":"Raised in newFileUploadRequest when multipart.Writer.WriteField fails while copying a form field (key '%q', value '%q') received in the presigned-URL response into the multipart form buffer. The inputs at fault come from the remote service's FormFields map. Failure is a local encoding/buffer-write error — essentially only possible if a field value contains invalid UTF-8 that the multipart writer rejects.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/storage/file_persister.go:217 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the persist to get a fresh presigned response with new form fields","Report as a bug if the cloud service consistently returns problematic field values","Verify no man-in-the-middle proxy is mangling the presigned response"],"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"}