{"record":{"id":"faef937fc1b5ff47","repo":"anomalyco/sst","slug":"failed-to-close-writer-w-faef93","errorCode":null,"errorMessage":"failed to close writer: %w","messagePattern":"failed to close writer: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/server/resource/cloudflare-worker-script.go","lineNumber":201,"sourceCode":"\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create form part metadata: %w\", err)\n\t}\n\n\tmetadata, err := json.Marshal(buildMetadata(input))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to marshal metadata: %w\", err)\n\t}\n\n\t_, err = metadataPart.Write(metadata)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to write file content for metadata: %w\", err)\n\t}\n\n\t// Close writer\n\terr = writer.Close()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to close writer: %w\", err)\n\t}\n\n\turl := fmt.Sprintf(\"https://api.cloudflare.com/client/v4/accounts/%s/workers/scripts/%s\", input.AccountId, input.ScriptName)\n\n\treq, err := http.NewRequest(\"PUT\", url, &body)\n\tif err != nil {\n\t\treturn err\n\t}\n\treq.Header.Set(\"Content-Type\", \"multipart/form-data; boundary=\"+writer.Boundary())\n\treq.Header.Set(\"Authorization\", \"Bearer \"+input.ApiToken)\n\n\tclient := &http.Client{Timeout: 30 * time.Second}\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer resp.Body.Close()\n","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/server/resource/cloudflare-worker-script.go#L183-L219","documentation":"Returned when multipart.Writer.Close() fails after all parts were written. Close finalizes the closing boundary into the bytes.Buffer and only errors if that final write fails. This is the last step of building the upload body in handleUpdate before the HTTP PUT to the Cloudflare Workers API.","triggerScenarios":"writer.Close() returns an error when writing the terminating multipart boundary into the bytes.Buffer.","commonSituations":"Memory/buffer failures; custom modifications to the body-building sequence.","solutions":["Verify all part writes completed before Close and Close is called exactly once","Inspect the wrapped inner error for buffer/allocation causes","Report upstream if it reproduces on an unmodified checkout"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"null","typeGuard":null,"tryCatchPattern":"if err := handleUpdate(input); err != nil {\n    if strings.Contains(err.Error(), \"failed to close writer\") {\n        return fmt.Errorf(\"multipart body incomplete: %w\", err)\n    }\n    return err\n}","preventionTips":["Call writer.Close() exactly once, after all parts","Set the request Content-Type from writer.Boundary() only after successful Close"],"tags":["cloudflare","multipart","go","workers"],"backgroundTag":"multipart-form-write-failed","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}