anomalyco/sst · error
failed to write file content for %s: %w
Error message
failed to write file content for %s: %w
What it means
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.
Source
Thrown at pkg/server/resource/cloudflare-worker-script.go:176
}
contentType := "application/javascript"
if input.MainModule != "" {
input.MainModule = input.Content.Hash
contentType = "application/javascript+module"
}
contentPart, err := writer.CreatePart(map[string][]string{
"Content-Disposition": []string{fmt.Sprintf(`form-data; name="%s"; filename="%s"`, input.Content.Hash, input.Content.Hash)},
"Content-Type": []string{contentType},
})
if err != nil {
return fmt.Errorf("failed to create form part %s: %w", input.Content.Hash, err)
}
_, err = contentPart.Write([]byte(fileContent))
if err != nil {
return fmt.Errorf("failed to write file content for %s: %w", input.Content.Hash, err)
}
// Add metadata to form data
metadataPart, err := writer.CreatePart(map[string][]string{
"Content-Disposition": []string{`form-data; name="metadata"`},
"Content-Type": []string{"application/json"},
})
if err != nil {
return fmt.Errorf("failed to create form part metadata: %w", err)
}
metadata, err := json.Marshal(buildMetadata(input))
if err != nil {
return fmt.Errorf("failed to marshal metadata: %w", err)
}
_, err = metadataPart.Write(metadata)
if err != nil {View on GitHub (pinned to a0bd20f762)
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
Example fix
null
Defensive patterns
Strategy: try-catch
Validate before calling
if _, err := os.Stat(input.Content.Filename); err != nil { return fmt.Errorf("worker file missing: %w", err) } Try / catch
if err := handleUpdate(input); err != nil {
if strings.Contains(err.Error(), "failed to write file content") {
log.Printf("buffer write failed, check bundle size/memory: %v", err)
}
return err
} Prevention
- 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
When it happens
Trigger: contentPart.Write([]byte(fileContent)) returns n < len(fileContent) or a non-nil error after the file was read from input.Content.Filename.
Common situations: Extremely large worker bundles exhausting memory; corrupted internal writer state after a prior partial failure; custom writer mutations.
Related errors
- failed to write encoded content for %s: %w
- failed to create form part %s: %w
- failed to write file content for metadata: %w
- failed to close writer: %w
- bucket %v upload failed: %w
AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30).
Data as JSON: /api/errors/8ba2ca235bc5c9a3.
Report an issue: GitHub.