{"record":{"id":"c4cab6c39782179a","repo":"kubernetes/kops","slug":"error-reading-data-v","errorCode":null,"errorMessage":"error reading data: %v","messagePattern":"error reading data: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/pkg/vfs/memfs.go","lineNumber":111,"sourceCode":"\t\tchild := current.children[token]\n\t\tif child == nil {\n\t\t\tchild = &MemFSPath{\n\t\t\t\tcontext:  p.context,\n\t\t\t\tlocation: path.Join(current.location, token),\n\t\t\t}\n\t\t\tcurrent.children[token] = child\n\t\t}\n\t\tcurrent = child\n\t\tcurrent.mutex.Lock()\n\t\tdefer current.mutex.Unlock()\n\t}\n\treturn current\n}\n\nfunc (p *MemFSPath) WriteFile(ctx context.Context, r io.ReadSeeker, acl ACL) error {\n\tdata, err := io.ReadAll(r)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error reading data: %v\", err)\n\t}\n\tp.contents = data\n\tp.acl = acl\n\treturn nil\n}\n\nfunc (p *MemFSPath) CreateFile(ctx context.Context, data io.ReadSeeker, acl ACL) error {\n\t// Check if exists\n\tif p.contents != nil {\n\t\treturn os.ErrExist\n\t}\n\n\treturn p.WriteFile(ctx, data, acl)\n}\n\n// ReadFile implements Path::ReadFile\nfunc (p *MemFSPath) ReadFile(ctx context.Context) ([]byte, error) {\n\tif p.contents == nil {","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/util/pkg/vfs/memfs.go#L93-L129","documentation":"MemFSPath.WriteFile reads the full contents from the provided io.ReadSeeker before storing them in the in-memory filesystem. This error wraps any failure from that read (e.g. an already-closed reader or an underlying read error).","triggerScenarios":"Calling WriteFile (directly or via vfs CreateFile/WriteTo) with an io.ReadSeeker whose Read fails — most commonly a reader already consumed and closed, or a failing bytes/string wrapper.","commonSituations":"Reusing a bytes.Reader/file after a prior upload exhausted it; passing a network-backed reader that errors mid-read when writing test clusters to memfs://.","solutions":["Ensure the io.ReadSeeker is freshly positioned/valid; recreate the reader (e.g. bytes.NewReader(data)) before each WriteFile","Check the wrapped %v error for the underlying read cause (e.g. 'file already closed') and fix the reader's lifecycle","If retrying, Seek the reader back to offset 0 first since WriteFile consumes the whole stream"],"exampleFix":"// before\nf, _ := os.Open(path); defer f.Close()\nupload(ctx, f) // second call fails: reader consumed/closed\n// after\nupload := func() error {\n    f, err := os.Open(path)\n    if err != nil { return err }\n    defer f.Close()\n    return upload(ctx, f)\n}","handlingStrategy":"validation","validationCode":"if rs, ok := r.(io.Seeker); ok { if _, err := rs.Seek(0, io.SeekStart); err != nil { return err } }","typeGuard":"null","tryCatchPattern":"if err := p.WriteFile(ctx, r, acl); err != nil {\n    if strings.HasPrefix(err.Error(), \"error reading data:\") {\n        // recreate reader and retry once\n    }\n    return err\n}","preventionTips":["Pass a fresh bytes.Reader for each WriteFile call","Never reuse a closed file/os.File as the ReadSeeker","Seek to 0 before re-uploading a ReadSeeker"],"tags":["vfs","memfs","io"],"backgroundTag":"read-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}