golangci/golangci-lint · error

failed to get file %s lines cache: %w

Error message

failed to get file %s lines cache: %w

What it means

Wrapping error in LineCache.getRawLine, called via GetLine: getFileCache(filePath) failed — underlying cause is usually the file byte cache failing to read the file (missing, unreadable) — so the requested line cannot be retrieved. The path and root cause are preserved via %w.

Source

Thrown at pkg/fsutils/linecache.go:40

// GetLine returns the index1-th (1-based index) line from the file on filePath
func (lc *LineCache) GetLine(filePath string, index1 int) (string, error) {
	if index1 == 0 { // some linters, e.g. gosec can do it: it really means first line
		index1 = 1
	}

	const index1To0Offset = -1
	rawLine, err := lc.getRawLine(filePath, index1+index1To0Offset)
	if err != nil {
		return "", err
	}

	return string(bytes.Trim(rawLine, "\r")), nil
}

func (lc *LineCache) getRawLine(filePath string, index0 int) ([]byte, error) {
	fc, err := lc.getFileCache(filePath)
	if err != nil {
		return nil, fmt.Errorf("failed to get file %s lines cache: %w", filePath, err)
	}

	if index0 < 0 {
		return nil, fmt.Errorf("invalid file line index0 < 0: %d", index0)
	}

	if index0 >= len(fc) {
		return nil, fmt.Errorf("invalid file line index0 (%d) >= len(fc) (%d)", index0, len(fc))
	}

	return fc[index0], nil
}

func (lc *LineCache) getFileCache(filePath string) (fileLinesCache, error) {
	loadedFc, ok := lc.files.Load(filePath)
	if ok {
		return loadedFc.(fileLinesCache), nil
	}

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Verify the source file exists and is readable
  2. Check the wrapped underlying error for the file-read failure
  3. Ensure the file was not removed while golangci-lint was running
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at pkg/fsutils/linecache.go:40 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/0096bc731a980c6c. Report an issue: GitHub.