{"record":{"id":"6538ec29b6ed00e6","repo":"anomalyco/sst","slug":"failed-to-create-form-part-s-w-6538ec","errorCode":null,"errorMessage":"failed to create form part %s: %w","messagePattern":"failed to create form part (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/server/resource/cloudflare-worker-script.go","lineNumber":171,"sourceCode":"\n\t// Add file content to form data\n\tfileContent, err := os.ReadFile(input.Content.Filename)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to read file %s: %w\", input.Content.Filename, err)\n\t}\n\n\tcontentType := \"application/javascript\"\n\tif input.MainModule != \"\" {\n\t\tinput.MainModule = input.Content.Hash\n\t\tcontentType = \"application/javascript+module\"\n\t}\n\n\tcontentPart, err := writer.CreatePart(map[string][]string{\n\t\t\"Content-Disposition\": []string{fmt.Sprintf(`form-data; name=\"%s\"; filename=\"%s\"`, input.Content.Hash, input.Content.Hash)},\n\t\t\"Content-Type\":        []string{contentType},\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create form part %s: %w\", input.Content.Hash, err)\n\t}\n\n\t_, err = contentPart.Write([]byte(fileContent))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to write file content for %s: %w\", input.Content.Hash, err)\n\t}\n\n\t// Add metadata to form data\n\tmetadataPart, err := writer.CreatePart(map[string][]string{\n\t\t\"Content-Disposition\": []string{`form-data; name=\"metadata\"`},\n\t\t\"Content-Type\":        []string{\"application/json\"},\n\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 {","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/server/resource/cloudflare-worker-script.go#L153-L189","documentation":"This error wraps a failure from mime/multipart.Writer.CreatePart while building the multipart body used to PUT a Worker script to the Cloudflare API. CreatePart only fails if the multipart writer was already closed or the underlying buffer cannot accept a new part header, so it is nearly always a programming/lifecycle bug rather than a user input problem. It is returned by handleUpdate, which backs both Create and Update of the WorkerScript resource.","triggerScenarios":"writer.CreatePart returns an error while creating the content part for input.Content.Hash — practically only when the multipart.Writer has already been Close()d, or an I/O error occurs writing headers into the underlying bytes.Buffer.","commonSituations":"Reordering the handleUpdate body so writer.Close() is called before CreatePart; writing additional parts after Close; an out-of-memory or closed-buffer condition making the bytes.Buffer write fail.","solutions":["Check that no code path calls writer.Close() before this CreatePart call; all CreatePart/Write calls must precede Close","Re-run the deploy — this is deterministic, so if it persists inspect custom modifications to cloudflare-worker-script.go","Report upstream with the wrapped inner error (%w) if it occurs on an unmodified checkout"],"exampleFix":"// before\nerr = writer.Close()\ncontentPart, err := writer.CreatePart(headers) // fails: writer closed\n// after\ncontentPart, err := writer.CreatePart(headers)\n// ... write all parts ...\nerr = writer.Close()","handlingStrategy":"try-catch","validationCode":"if input.Content.Hash == \"\" { return errors.New(\"content hash required before upload\") }","typeGuard":null,"tryCatchPattern":"err := r.handleUpdate(input)\nif err != nil {\n    var wrap *fmt.wrapError\n    if errors.As(err, &wrap) { log.Printf(\"multipart failure: %v\", wrap.Unwrap()) }\n    return err\n}","preventionTips":["Never call writer.Close() before all CreatePart/Write calls","Keep part creation and writes in a single linear function","Add a test that builds the multipart body end-to-end"],"tags":["cloudflare","multipart","workers","go"],"backgroundTag":"multipart-form-write-failed","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}