golangci/golangci-lint · error
read directory: %w
Error message
read directory: %w
What it means
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.
Source
Thrown at pkg/commands/internal/configuration.go:121
return nil, fmt.Errorf("file %s open: %w", configFilePath, err)
}
defer func() { _ = file.Close() }()
var cfg Configuration
err = yaml.NewDecoder(file).Decode(&cfg)
if err != nil {
return nil, fmt.Errorf("YAML decoding: %w", err)
}
return &cfg, nil
}
func findConfigurationFile() (string, error) {
entries, err := os.ReadDir(".")
if err != nil {
return "", fmt.Errorf("read directory: %w", err)
}
for _, entry := range entries {
ext := filepath.Ext(entry.Name())
switch strings.ToLower(strings.TrimPrefix(ext, ".")) {
case "yml", "yaml", "json":
if isConf(ext, entry.Name()) {
return entry.Name(), nil
}
}
}
return "", errors.New("configuration file not found")
}
func isConf(ext, name string) bool {
return base+ext == nameView on GitHub (pinned to ed7a235d2d)
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
Example fix
// before $ cd $(mktemp -d) && rm -rf $PWD && tool # CWD deleted // after $ cd ~/projects/myapp && tool
Defensive patterns
Strategy: validation
Validate before calling
wd, err := os.Getwd()
if err != nil { return err }
if _, err := os.ReadDir(wd); err != nil {
return fmt.Errorf("working directory %s is unreadable/deleted: %w — cd to the project root first", wd, err)
} Try / catch
cfg, err := LoadConfiguration()
if err != nil {
var perr *fs.PathError
if errors.As(err, &perr) && errors.Is(perr, fs.ErrPermission) {
log.Fatalf("cannot read %s: permission denied — check directory permissions or run from another directory", perr.Path)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- create destination directory: %w
- file %s not found: %w
- %s is not a directory
- write file %s: %w
- writing file %s: %w
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/3b976d4a26d78714.
Report an issue: GitHub.