{"record":{"id":"3b976d4a26d78714","repo":"golangci/golangci-lint","slug":"read-directory-w","errorCode":null,"errorMessage":"read directory: %w","messagePattern":"read directory: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/internal/configuration.go","lineNumber":121,"sourceCode":"\t\treturn nil, fmt.Errorf(\"file %s open: %w\", configFilePath, err)\n\t}\n\n\tdefer func() { _ = file.Close() }()\n\n\tvar cfg Configuration\n\n\terr = yaml.NewDecoder(file).Decode(&cfg)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"YAML decoding: %w\", err)\n\t}\n\n\treturn &cfg, nil\n}\n\nfunc findConfigurationFile() (string, error) {\n\tentries, err := os.ReadDir(\".\")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"read directory: %w\", err)\n\t}\n\n\tfor _, entry := range entries {\n\t\text := filepath.Ext(entry.Name())\n\n\t\tswitch strings.ToLower(strings.TrimPrefix(ext, \".\")) {\n\t\tcase \"yml\", \"yaml\", \"json\":\n\t\t\tif isConf(ext, entry.Name()) {\n\t\t\t\treturn entry.Name(), nil\n\t\t\t}\n\t\t}\n\t}\n\n\treturn \"\", errors.New(\"configuration file not found\")\n}\n\nfunc isConf(ext, name string) bool {\n\treturn base+ext == name","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/internal/configuration.go#L103-L139","documentation":"findConfigurationFile lists the current directory with os.ReadDir(\".\") to discover a configuration file; this wrapper reports 'read directory'. The config search itself failed because the current working directory could not be read — typically it no longer exists or is unreadable.","triggerScenarios":"os.ReadDir(\".\") fails when the process's working directory was deleted while the program ran, the directory lacks read permission for the current user, or a sandbox/container restricts directory listing.","commonSituations":"Running the tool from a tmpdir that a wrapper script deletes, starting the CLI from a directory later removed (common with CI workspaces), running inside a container with a restricted user, or executing with CWD on an unmounted volume.","solutions":["Run the tool from an existing, readable project directory (pwd to confirm CWD is valid)","Check permissions on the current directory: chmod +rx . or run as a user with access","If a script deletes the CWD before invoking the tool, reorder steps or cd to a stable directory first","Inspect the wrapped *os.PathError: ENOENT means the directory was removed; EACCES means permissions"],"exampleFix":"// before\n$ cd $(mktemp -d) && rm -rf $PWD && tool   # CWD deleted\n// after\n$ cd ~/projects/myapp && tool","handlingStrategy":"validation","validationCode":"wd, err := os.Getwd()\nif err != nil { return err }\nif _, err := os.ReadDir(wd); err != nil {\n    return fmt.Errorf(\"working directory %s is unreadable/deleted: %w — cd to the project root first\", wd, err)\n}","typeGuard":null,"tryCatchPattern":"cfg, err := LoadConfiguration()\nif err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) && errors.Is(perr, fs.ErrPermission) {\n        log.Fatalf(\"cannot read %s: permission denied — check directory permissions or run from another directory\", perr.Path)\n    }\n    return err\n}","preventionTips":["Do not delete the directory the tool is running from (watch tempdir-cleanup scripts)","Confirm pwd resolves before invoking the tool in scripts and CI steps","Ensure the executing user has read+execute on the working directory","Run from a stable project checkout rather than ephemeral or unmounted paths"],"tags":["go","filesystem","readdir","cwd"],"backgroundTag":"directory-not-found","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}