{"record":{"id":"b64ae50ed31fcd75","repo":"gofiber/fiber","slug":"failed-to-copy-file-data-w","errorCode":null,"errorMessage":"failed to copy file data: %w","messagePattern":"failed to copy file data: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/hooks.go","lineNumber":322,"sourceCode":"\tif f.reader == nil {\n\t\tvar err error\n\t\tf.reader, err = os.Open(f.path)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"open file error: %w\", err)\n\t\t}\n\t}\n\n\t// Ensure the file reader is always closed after copying.\n\tdefer f.reader.Close() //nolint:errcheck // not needed\n\n\t// Create form file and copy the content.\n\tw, err := mw.CreateFormFile(f.fieldName, f.name)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"create file error: %w\", err)\n\t}\n\n\tif _, err := io.CopyBuffer(w, f.reader, *fileBuf); err != nil {\n\t\treturn fmt.Errorf(\"failed to copy file data: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// parserResponseCookie parses the Set-Cookie headers from the response and stores them.\nfunc parserResponseCookie(c *Client, resp *Response, req *Request) error {\n\tvar err error\n\tfor key, value := range resp.RawResponse.Header.Cookies() {\n\t\tcookie := fasthttp.AcquireCookie()\n\t\tif err = cookie.ParseBytes(value); err != nil {\n\t\t\tfasthttp.ReleaseCookie(cookie)\n\t\t\tbreak\n\t\t}\n\t\tcookie.SetKeyBytes(key)\n\t\tresp.cookie = append(resp.cookie, cookie)\n\t}\n","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/client/hooks.go#L304-L340","documentation":"addFormFile copies the file content into the multipart part via io.CopyBuffer. This wraps a failure of that copy: a read error from the file (disk I/O, read after close) or a write error from the multipart writer (body buffer/pipe failed).","triggerScenarios":"The file is read during send and the underlying disk returns an error; the file reader was closed by another goroutine mid-copy; the body writer's write side fails (broken pipe, buffer overflow on streaming).","commonSituations":"Network-backed or FUSE filesystems that error mid-read; concurrent close of the file handle; uploading from a stream whose producer errored; very large files where a transient I/O fault occurs.","solutions":["If using SetReader, ensure the reader stays open and readable for the whole send.","Inspect the wrapped cause to distinguish read (file) vs write (body) failures.","Retry idempotent uploads on transient I/O errors; surface permanent ones to the caller."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := c.Post(url, req); err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) { /* disk read failure */ }\n}","preventionTips":["Keep SetReader handles open and readable until the send completes.","Distinguish read vs write failures via the wrapped cause before retrying.","Retry only idempotent uploads on transient I/O errors."],"tags":["client","multipart","io","file-upload","copy"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}