golangci/golangci-lint · error
failed to compute go.sum: %w
Error message
failed to compute go.sum: %w
What it means
After reading go.mod, computeGoModSalt computes a dirhash.Hash1 over its contents. If dirhash.Hash1 itself errors (unexpected here since it hashes an in-memory single file), the failure is wrapped with this message, again aborting hash-salt computation.
Source
Thrown at pkg/commands/run.go:721
func computeGoModSalt() (string, error) {
values, err := goenv.Get(context.Background(), goenv.GOMOD)
if err != nil {
return "", fmt.Errorf("failed to get goenv: %w", err)
}
goModPath := filepath.Clean(values[goenv.GOMOD])
data, err := os.ReadFile(goModPath)
if err != nil {
return "", fmt.Errorf("failed to read go.mod: %w", err)
}
// NOTE: the variable `goModPath` is not used here to ensure getting the same hash, independently of the location, for the same content.
sum, err := dirhash.Hash1([]string{"go.mod"}, func(string) (io.ReadCloser, error) {
return io.NopCloser(bytes.NewReader(data)), nil
})
if err != nil {
return "", fmt.Errorf("failed to compute go.sum: %w", err)
}
return sum, nil
}
View on GitHub (pinned to ed7a235d2d)
Solutions
- Inspect the wrapped cause in the error message for the real failure
- Update to a recent golangci-lint version to rule out a stdlib/dirhash regression
- If persistent, clear the lint cache (`golangci-lint cache clean`) and retry
Defensive patterns
Strategy: try-catch
Try / catch
if err := runLint(); err != nil {
if strings.Contains(err.Error(), "failed to compute go.sum") {
// inspect wrapped cause; clear cache and retry once
runCacheClean()
err = runLint()
}
if err != nil {
log.Fatal(err)
}
} Prevention
- Keep golangci-lint and Go toolchain versions up to date
- If seen repeatedly, run `golangci-lint cache clean` and retry
- Report persistent occurrences with the wrapped cause to maintainers
When it happens
Trigger: dirhash.Hash1 failing during cache salt initialization; in practice nearly unreachable because the Open function returns io.NopCloser over an in-memory reader that cannot fail.
Common situations: Theoretically surfaced in exotic environments where the stdlib dirhash implementation returns an error; developers seeing it should check the wrapped cause.
Related errors
- failed to calculate binary salt: %w
- failed to read go.mod: %w
- can't load config: %w
- can't get enabled linters: %w
- failed to build packages cache: %w
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/c8188d34044aad0c.
Report an issue: GitHub.