{"record":{"id":"f3d7b7090d863a64","repo":"golangci/golangci-lint","slug":"s-file-open-w","errorCode":null,"errorMessage":"[%s] file open: %w","messagePattern":"\\[(.+?)\\] file open: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/config_verify.go","lineNumber":96,"sourceCode":"\nfunc printValidationDetail(cmd *cobra.Command, detail *jsonschema.OutputUnit) {\n\tif detail.Error != nil {\n\t\tdata, _ := json.Marshal(detail.Error)\n\t\tdetails, _ := strconv.Unquote(string(data))\n\n\t\tcmd.PrintErrf(\"jsonschema: %q does not validate with %q: %s\\n\",\n\t\t\tstrings.ReplaceAll(strings.TrimPrefix(detail.InstanceLocation, \"/\"), \"/\", \".\"), detail.KeywordLocation, details)\n\t}\n\n\tfor _, d := range detail.Errors {\n\t\tprintValidationDetail(cmd, &d)\n\t}\n}\n\nfunc decodeYamlFile(filename string) (any, error) {\n\tfile, err := os.Open(filename)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] file open: %w\", filename, err)\n\t}\n\n\tdefer func() { _ = file.Close() }()\n\n\tvar m any\n\terr = yaml.NewDecoder(file).Decode(&m)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] YAML decode: %w\", filename, err)\n\t}\n\n\treturn m, nil\n}\n\nfunc decodeTomlFile(filename string) (any, error) {\n\tfile, err := os.Open(filename)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] file open: %w\", filename, err)\n\t}","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/config_verify.go#L78-L114","documentation":"decodeYamlFile opens the target config file with os.Open before YAML-decoding it for schema validation. If the file cannot be opened, the error is wrapped as \"[%s] file open: %w\" including the filename. It is called from validateConfiguration during config verify.","triggerScenarios":"os.Open(filename) fails inside decodeYamlFile — path doesn't exist, wrong permissions, or it's a directory — when running the verify flow on a .yaml/.yml/.json config.","commonSituations":"Typos in the config path passed to `config verify`; running from a different working directory; file deleted between edit and verify; restricted CI permissions.","solutions":["Check the filename in the error and verify the file exists at that path (ls <path>)","Run verify from the project root or pass an absolute path to the config file","Fix file permissions if access is denied (chmod/chown)","Ensure the path is a regular file, not a directory"],"exampleFix":"// before\n$ golangci-lint config verify .golangci.yaml  # file is actually .golangci.yml\n// [.golangci.yaml] file open: no such file or directory\n\n// after\n$ golangci-lint config verify .golangci.yml","handlingStrategy":"validation","validationCode":"func assertReadableFile(path string) error {\n    info, err := os.Stat(path)\n    if err != nil {\n        return fmt.Errorf(\"config file missing/unreachable: %w\", err)\n    }\n    if info.IsDir() {\n        return fmt.Errorf(\"%s is a directory, expected a file\", path)\n    }\n    f, err := os.Open(path)\n    if err != nil {\n        return fmt.Errorf(\"no read permission on %s: %w\", path, err)\n    }\n    _ = f.Close()\n    return nil\n}","typeGuard":"func isFileOpenError(err error) (string, bool) {\n    var pe *os.PathError\n    if errors.As(err, &pe) {\n        return pe.Path, true\n    }\n    return \"\", false\n}","tryCatchPattern":"m, err := decodeYamlFile(filename)\nif err != nil {\n    var pe *os.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, os.ErrNotExist) {\n        return fmt.Errorf(\"config %s not found — check the path passed to verify\", filename)\n    }\n    return fmt.Errorf(\"[%s] file open: %w\", filename, err)\n}","preventionTips":["Use absolute paths or run from the project root","Double-check the config filename/extension before invoking verify","Ensure CI checkouts actually include the config file","Verify read permissions for the user running the tool"],"tags":["filesystem","config","yaml"],"backgroundTag":"file-open-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}