{"record":{"id":"54d6aa68baeccb11","repo":"kubernetes/kops","slug":"error-reading-file-q-v-54d6aa","errorCode":null,"errorMessage":"error reading file %q: %v","messagePattern":"error reading file %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/replace.go","lineNumber":104,"sourceCode":"func RunReplace(ctx context.Context, f *util.Factory, out io.Writer, c *ReplaceOptions) error {\n\tclientset, err := f.KopsClient()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvfsContext := f.VFSContext()\n\n\tfor _, f := range c.Filenames {\n\t\tvar contents []byte\n\t\tif f == \"-\" {\n\t\t\tcontents, err = ConsumeStdin()\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t} else {\n\t\t\tcontents, err = vfsContext.ReadFile(f)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error reading file %q: %v\", f, err)\n\t\t\t}\n\t\t}\n\t\tsections := text.SplitContentToSections(contents)\n\n\t\tfor _, section := range sections {\n\t\t\to, gvk, err := kopscodecs.Decode(section, nil)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error parsing file %q: %v\", f, err)\n\t\t\t}\n\n\t\t\tswitch v := o.(type) {\n\t\t\tcase *kopsapi.Cluster:\n\t\t\t\t{\n\t\t\t\t\t// Retrieve the current status of the cluster.  This will eventually be part of the cluster object.\n\t\t\t\t\tcloud, err := cloudup.BuildCloud(v)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/replace.go#L86-L122","documentation":"kops `kops replace -f FILE` reads each manifest through the VFS layer (vfsContext.ReadFile) before decoding. This error wraps any read failure - missing file, permission denied, or a VFS scheme (s3://, gs://) that failed or is not configured.","triggerScenarios":"Running `kops replace -f` with a path that does not exist, a typo'd path, no read permission, an unreadable remote VFS path (e.g. s3:// bucket not present/accessible), or stdin handled elsewhere while a bad filename is passed.","commonSituations":"Running the command from a different working directory than expected; forgetting the file was deleted or renamed; ~/.aws or gcloud credentials missing so a cloud-backed VFS path cannot be read; using a relative path in CI.","solutions":["Verify the file path exists and is readable: ls -l <file>; fix typos in the -f argument","Use an absolute path or run from the correct directory","For remote paths (s3://, gs://), confirm the object exists and cloud credentials/env are configured","If intending stdin, pass exactly `-f -` and pipe the manifest","Check the underlying error text in the message for the precise cause (no such file, permission denied, etc.)"],"exampleFix":"// before\nkops replace -f ./cluter.yaml\n// after\nkops replace -f ./cluster.yaml","handlingStrategy":"validation","validationCode":"for _, f := range filenames {\n    if f != \"-\" {\n        if _, err := os.Stat(f); err != nil {\n            return fmt.Errorf(\"manifest not readable: %w\", err)\n        }\n    }\n}\n// For remote VFS paths, ensure credentials and the target object exist first.","typeGuard":null,"tryCatchPattern":"if err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) { /* handle missing/unreadable file */ }\n    return err\n}","preventionTips":["Use absolute paths in scripts/CI","Check file existence before invoking kops replace","Keep cloud credentials configured when using s3:// or gs:// manifests","Pipe via -f - and verify exit codes when generating manifests dynamically"],"tags":["filesystem","cli","io"],"backgroundTag":"file-not-found","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"}