{"record":{"id":"8ba2ca235bc5c9a3","repo":"anomalyco/sst","slug":"failed-to-write-file-content-for-s-w","errorCode":null,"errorMessage":"failed to write file content for %s: %w","messagePattern":"failed to write file content for (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/server/resource/cloudflare-worker-script.go","lineNumber":176,"sourceCode":"\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 {\n\t\treturn fmt.Errorf(\"failed to marshal metadata: %w\", err)\n\t}\n\n\t_, err = metadataPart.Write(metadata)\n\tif err != nil {","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/server/resource/cloudflare-worker-script.go#L158-L194","documentation":"This error is returned when writing the Worker script file bytes into the multipart form part fails. The Write targets an in-memory bytes.Buffer via the multipart part writer, so failure indicates the buffer write returned an error (e.g. allocation failure), not a network problem. It is raised inside handleUpdate during Create/Update of the WorkerScript resource.","triggerScenarios":"contentPart.Write([]byte(fileContent)) returns n < len(fileContent) or a non-nil error after the file was read from input.Content.Filename.","commonSituations":"Extremely large worker bundles exhausting memory; corrupted internal writer state after a prior partial failure; custom writer mutations.","solutions":["Check the wrapped inner error for an allocation/OOM cause and reduce the worker bundle size","Verify all writes happen before writer.Close()","Re-run the deploy; retry transiently if memory pressure caused it"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(input.Content.Filename); err != nil { return fmt.Errorf(\"worker file missing: %w\", err) }","typeGuard":null,"tryCatchPattern":"if err := handleUpdate(input); err != nil {\n    if strings.Contains(err.Error(), \"failed to write file content\") {\n        log.Printf(\"buffer write failed, check bundle size/memory: %v\", err)\n    }\n    return err\n}","preventionTips":["Keep worker bundles small to avoid memory pressure","Retry deploy once on transient failures","Avoid mutating the bytes.Buffer concurrently while the writer uses it"],"tags":["cloudflare","multipart","io","workers"],"backgroundTag":"multipart-form-write-failed","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}