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 == name

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Run the tool from an existing, readable project directory (pwd to confirm CWD is valid)
  2. Check permissions on the current directory: chmod +rx . or run as a user with access
  3. If a script deletes the CWD before invoking the tool, reorder steps or cd to a stable directory first
  4. 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

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


AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02). Data as JSON: /api/errors/3b976d4a26d78714. Report an issue: GitHub.