{"record":{"id":"6837b85e84870373","repo":"kubernetes/kops","slug":"reading-data-v-6837b8","errorCode":null,"errorMessage":"reading data: %v","messagePattern":"reading data: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/pkg/vfs/s3fs.go","lineNumber":705,"sourceCode":"type terraformDOFile struct {\n\tBucket  string                   `json:\"bucket\" cty:\"bucket\"`\n\tRegion  string                   `json:\"region\" cty:\"region\"`\n\tKey     string                   `json:\"key\" cty:\"key\"`\n\tContent *terraformWriter.Literal `json:\"content,omitempty\" cty:\"content\"`\n}\n\ntype terraformScwFile struct {\n\tBucket  string                   `json:\"bucket\" cty:\"bucket\"`\n\tKey     string                   `json:\"key\" cty:\"key\"`\n\tContent *terraformWriter.Literal `json:\"content,omitempty\" cty:\"content\"`\n}\n\nfunc (p *S3Path) RenderTerraform(w *terraformWriter.TerraformWriter, name string, data io.Reader, acl ACL) error {\n\tctx := context.TODO()\n\n\tbytes, err := io.ReadAll(data)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"reading data: %v\", err)\n\t}\n\n\t// render DO's terraform\n\tswitch p.scheme {\n\tcase \"do\":\n\n\t\tcontent, err := w.AddFileBytes(\"digitalocean_spaces_bucket_object\", name, \"content\", bytes, false)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error rendering DO file: %w\", err)\n\t\t}\n\n\t\t// retrieve space region from endpoint\n\t\tendpoint := os.Getenv(\"S3_ENDPOINT\")\n\t\tif endpoint == \"\" {\n\t\t\treturn errors.New(\"S3 Endpoint is empty\")\n\t\t}\n\t\tregion := strings.Split(endpoint, \".\")[0]\n","sourceCodeStart":687,"sourceCodeEnd":723,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/util/pkg/vfs/s3fs.go#L687-L723","documentation":"S3Path.RenderTerraform (used by the DigitalOcean Spaces backend) first buffers the entire input with io.ReadAll. This error is returned when reading from the supplied io.Reader fails before any Terraform rendering starts — no data was consumed from the caller's reader beyond the failure point.","triggerScenarios":"Calling RenderTerraform (indirectly via terraform writers that pass an io.Reader) with a reader backed by a failing source: an already-closed file, a failed HTTP body, or an OS I/O error during the read.","commonSituations":"Terraform output generation where a config file was truncated or unreadable on disk; passing a response body that already errored upstream; permissions issues on local cluster state files.","solutions":["Fix the underlying reader: check that the source file exists, is readable, and is opened before calling RenderTerraform.","If the reader wraps a network body, read/validate it yourself first and handle errors before rendering.","Read the wrapped %v cause in the message to identify whether it's a permissions, EOF, or closed-stream error.","Where possible pass in-memory bytes ([]byte reader) to eliminate reader-side failure modes."],"exampleFix":"// before\nerr := p.RenderTerraform(w, name, bytes.NewReader(data), acl)\n// replaced failing file reader\ndata, err := os.ReadFile(configPath)\nif err != nil { return err } // fail early with a clear error\nerr = p.RenderTerraform(w, name, bytes.NewReader(data), acl)","handlingStrategy":"validation","validationCode":"// fail fast if the source reader cannot provide data\nif f, ok := data.(*os.File); ok {\n    if _, err := f.Stat(); err != nil || f == nil { return fmt.Errorf(\"unusable reader: %w\", err) }\n}\n// or buffer it yourself first:\nbuf, err := io.ReadAll(data)\nif err != nil { return err } // surface the reader error with your own context","typeGuard":null,"tryCatchPattern":"bytes, err := io.ReadAll(data)\nif err != nil { return fmt.Errorf(\"preflight read of terraform input: %w\", err) }\nerr = p.RenderTerraform(w, name, bytes.NewReader(buf), acl) // in-memory readers can't fail here","preventionTips":["Pass bytes.NewReader on already-loaded data instead of live file/network readers.","Stat/check files before opening them as render inputs.","Handle reader errors upstream where you have context about the source.","Never reuse a response body reader after a prior error."],"tags":["io","reader","terraform","digitalocean"],"backgroundTag":"io-read-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}