{"record":{"id":"61ab83cafb6109c1","repo":"kubernetes/kops","slug":"error-reading-file-q-v","errorCode":null,"errorMessage":"error reading file %q: %v","messagePattern":"error reading file %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/create.go","lineNumber":121,"sourceCode":"\tclusterName := \"\"\n\t// var cSpec = false\n\tvar sb bytes.Buffer\n\tfmt.Fprintf(&sb, \"\\n\")\n\n\tvar addons kubemanifest.ObjectList\n\tvar clusters []*kopsapi.Cluster\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\t// TODO: this does not support a JSON array\n\t\tsections := text.SplitContentToSections(contents)\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\tcloud, err := cloudup.BuildCloud(v)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\n\t\t\t\t// Adding a PerformAssignments() call here as the user might be trying to use","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/create.go#L103-L139","documentation":"`kops create -f` reads each input file via vfsContext.ReadFile (local path or URL). If the file cannot be read (missing file, bad URL, permission denied), the error is wrapped as \"error reading file %q: %v\".","triggerScenarios":"Running `kops create -f <path>` where the path does not exist, is misspelled, is unreadable (permissions), or an http(s)/s3 URL fails to fetch.","commonSituations":"Typos in the -f argument, running from the wrong working directory, forgetting the file is on a remote location not reachable without cloud credentials, or reading a directory instead of a file.","solutions":["Verify the file path/URL is correct and the file exists (ls / curl the path)","Run from the directory containing the manifest or use an absolute path","Check file read permissions; add cloud credentials if using vfs URLs (s3://, gs://)","If passing a directory, list individual files instead"],"exampleFix":"// before\nkops create -f ./cluser.yaml\n// after\nkops create -f ./cluster.yaml","handlingStrategy":"validation","validationCode":"f := \"./cluster.yaml\"\nif _, err := os.Stat(f); err != nil {\n    log.Fatalf(\"input file %q not readable: %v\", f, err)\n}","typeGuard":null,"tryCatchPattern":"if err := runCreate(); err != nil {\n    if strings.Contains(err.Error(), \"error reading file\") {\n        // surface path & cwd to the user before retrying\n    }\n}","preventionTips":["Use absolute paths or run from the manifest's directory","Pre-check file existence/permissions before invoking `kops create -f`","Verify credentials before using s3://, gs://, or https:// input URLs","Do not pass directories to -f"],"tags":["cli","file-io","kops-create"],"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-12T12:17:11.808Z"}