golangci/golangci-lint · error

can't read file %s: %w

Error message

can't read file %s: %w

What it means

Error from FileCache.GetFileBytes: os.ReadFile failed for the requested path — the file does not exist, lacks read permission, or is a directory. The path is embedded via %s and the os error wrapped with %w. Generic I/O guard at the file-cache layer.

Source

Thrown at pkg/fsutils/filecache.go:27

)

type FileCache struct {
	files sync.Map
}

func NewFileCache() *FileCache {
	return &FileCache{}
}

func (fc *FileCache) GetFileBytes(filePath string) ([]byte, error) {
	cachedBytes, ok := fc.files.Load(filePath)
	if ok {
		return cachedBytes.([]byte), nil
	}

	fileBytes, err := os.ReadFile(filePath)
	if err != nil {
		return nil, fmt.Errorf("can't read file %s: %w", filePath, err)
	}

	fc.files.Store(filePath, fileBytes)
	return fileBytes, nil
}

func PrettifyBytesCount(n int64) string {
	const (
		Multiplexer = 1024
		KiB         = 1 * Multiplexer
		MiB         = KiB * Multiplexer
		GiB         = MiB * Multiplexer
	)

	if n >= GiB {
		return fmt.Sprintf("%.1fGiB", float64(n)/GiB)
	}
	if n >= MiB {

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Verify the file path exists and is a regular file
  2. Check file read permissions
  3. Run golangci-lint from the correct working directory
  4. Ensure paths in config (e.g. include/exclude patterns resolving to files) are valid
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at pkg/fsutils/filecache.go:27 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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