{"record":{"id":"755f8d7b5fe4560e","repo":"anomalyco/sst","slug":"failed-to-read-file-s-w-755f8d","errorCode":null,"errorMessage":"failed to read file %s: %w","messagePattern":"failed to read file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/server/resource/cloudflare-worker-script.go","lineNumber":157,"sourceCode":"}\n\nfunc (r *WorkerScript) Delete(input *DeleteInput[WorkerScriptOutputs], output *int) error {\n\terr := r.handleDelete(&input.Outs)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\nfunc (r *WorkerScript) handleUpdate(input *WorkerScriptInputs) error {\n\tvar body bytes.Buffer\n\twriter := multipart.NewWriter(&body)\n\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 {","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/server/resource/cloudflare-worker-script.go#L139-L175","documentation":"handleUpdate builds a multipart request to upload the worker script to Cloudflare and first reads the local script file (input.Content.Filename). This error wraps os.ReadFile failure: the file does not exist, the path is wrong, or the process lacks read permission. The wrapped os error names the exact reason.","triggerScenarios":"os.ReadFile(input.Content.Filename) fails in handleUpdate (pkg/server/resource/cloudflare-worker-script.go:157), invoked from Create/Update when the bundled worker script cannot be found at the recorded path on disk.","commonSituations":"Deploying from a different working directory or machine than where the build emitted the script; stale .sst state referencing a file cleaned by a rebuild; file deleted between build and deploy; read permissions on CI; path containing ~ that was never expanded.","solutions":["Check the path in the error exists: ls the reported filename","Rebuild (sst build / redeploy) so the output artifact is regenerated at the expected path","Run the CLI from the project root so relative paths resolve correctly","Fix file permissions (chmod) or run under an account that can read the file","Expand ~ or absolute-ize the path before storing it in state"],"exampleFix":"// before\nfileContent, err := os.ReadFile(input.Content.Filename)\nif err != nil {\n\treturn fmt.Errorf(\"failed to read file %s: %w\", input.Content.Filename, err)\n}\n// after\npath := input.Content.Filename\nif strings.HasPrefix(path, \"~\") {\n\thome, _ := os.UserHomeDir()\n\tpath = filepath.Join(home, strings.TrimPrefix(path, \"~\"))\n}\nif _, err := os.Stat(path); os.IsNotExist(err) {\n\treturn fmt.Errorf(\"worker script %q does not exist; run a build before deploy\", path)\n}\nfileContent, err := os.ReadFile(path)\nif err != nil {\n\treturn fmt.Errorf(\"failed to read file %s: %w\", path, err)\n}","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(input.Content.Filename); err != nil {\n\treturn fmt.Errorf(\"worker script %s unavailable before upload: %w\", input.Content.Filename, err)\n}","typeGuard":"func fileReadable(path string) bool {\n\tf, err := os.Open(path)\n\tif err != nil {\n\t\treturn false\n\t}\n\tf.Close()\n\treturn true\n}","tryCatchPattern":"fileContent, err := os.ReadFile(input.Content.Filename)\nif err != nil {\n\tif os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"worker script %s not found; run build first\", input.Content.Filename)\n\t}\n\treturn fmt.Errorf(\"failed to read file %s: %w\", input.Content.Filename, err)\n}","preventionTips":["Always build before deploy so the script artifact exists","Run the CLI from the project root so relative paths resolve","Expand ~ and use absolute paths in state","Check file permissions in CI environments"],"tags":["filesystem","cloudflare","worker-script","deploy"],"backgroundTag":"file-not-found","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}