{"record":{"id":"0a531d70b770a340","repo":"anomalyco/sst","slug":"failed-to-create-form-part-metadata-w","errorCode":null,"errorMessage":"failed to create form part metadata: %w","messagePattern":"failed to create form part metadata: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/server/resource/cloudflare-worker-script.go","lineNumber":185,"sourceCode":"\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 {\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","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/server/resource/cloudflare-worker-script.go#L167-L203","documentation":"Wraps an error from mime/multipart.Writer.CreatePart when creating the 'metadata' form part of the Cloudflare Worker script upload. As with the content part, CreatePart only fails on a closed writer or buffer I/O error. Raised in handleUpdate during Create/Update.","triggerScenarios":"writer.CreatePart for the 'metadata' part (Content-Type application/json) returns an error — effectively only if the writer was already closed or the bytes.Buffer write failed.","commonSituations":"Code reordering that closes the writer early; internal buffer failures; custom forks of the resource code.","solutions":["Ensure writer.Close() happens only after all CreatePart/Write calls","Inspect the wrapped error; it is deterministic, not transient","Report upstream if reproducible on unmodified code"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"null","typeGuard":null,"tryCatchPattern":"if err := handleUpdate(input); err != nil {\n    if strings.Contains(err.Error(), \"failed to create form part metadata\") {\n        return fmt.Errorf(\"worker upload body construction failed (report bug): %w\", err)\n    }\n    return err\n}","preventionTips":["Do not close the writer before creating the metadata part","Treat this as an internal invariant failure, not a user-input problem"],"tags":["cloudflare","multipart","metadata","go"],"backgroundTag":"multipart-form-write-failed","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}