golangci/golangci-lint · error
error while running %s: %w
Error message
error while running %s: %w
What it means
A configured formatter (gofmt, gofumpt, goimports, gci, etc.) returned an error while formatting the file's bytes. golangci-lint wraps the failure with the formatter's name so the user knows which formatter failed. This is a formatter-internal failure, not a lint finding.
Source
Thrown at pkg/goformatters/analyzer.go:36
func NewAnalyzer(logger logutils.Log, doc string, formatter Formatter) *analysis.Analyzer {
return &analysis.Analyzer{
Name: formatter.Name(),
Doc: doc,
Run: func(pass *analysis.Pass) (any, error) {
for _, file := range pass.Files {
position, isGoFile := goanalysis.GetGoFilePosition(pass, file)
if !isGoFile {
continue
}
input, err := os.ReadFile(position.Filename)
if err != nil {
return nil, fmt.Errorf("unable to open file %s: %w", position.Filename, err)
}
output, err := formatter.Format(position.Filename, input)
if err != nil {
return nil, fmt.Errorf("error while running %s: %w", formatter.Name(), err)
}
if !bytes.Equal(input, output) {
newName := filepath.ToSlash(position.Filename)
oldName := newName + ".orig"
patch := diff.Diff(oldName, input, newName, output)
err = internal.ExtractDiagnosticFromPatch(pass, file, patch, logger)
if err != nil {
return nil, fmt.Errorf("can't extract issues from %s diff output %q: %w", formatter.Name(), patch, err)
}
}
}
return nil, nil
},
}View on GitHub (pinned to ed7a235d2d)
Solutions
- Fix the syntax errors in the offending file (`go build`/`gofmt -l` to locate)
- Check formatter settings under formatters section of .golangci.yml for invalid options
- Update or pin a compatible formatter version in go.mod tools
- Exclude the problematic file via formatters.exclusions.paths if it is intentionally invalid
Example fix
# before: formatter option typo
formatters:
settings:
goimports:
local-prefixes: [unclosed
# after
formatters:
settings:
goimports:
local-prefixes:
- github.com/my/org Defensive patterns
Strategy: validation
Validate before calling
// ensure the file parses before formatter runs
if _, err := parser.ParseFile(fset, path, nil, parser.AllErrors); err != nil {
log.Fatalf("invalid Go source: %v", err)
} Try / catch
// identify which formatter failed from the wrapped message
if strings.Contains(err.Error(), "error while running gofumpt") {
// fix file syntax or gofumpt settings
} Prevention
- Keep formatter versions pinned and updated
- Validate formatter settings in .golangci.yml
- Exclude intentionally-invalid placeholder files
When it happens
Trigger: formatter.Format(filename, input) returns non-nil — e.g. gofumpt/goimports choke on syntactically invalid Go source, or a formatter subprocess/config option is invalid.
Common situations: Linting files with intentional syntax errors or placeholder code; incompatible formatter version pinned in tools; invalid formatter settings in .golangci.yml (e.g. bad goimports local-prefixes).
Related errors
- can't get enabled formatters: %w
- failed to create meta-formatter: %w
- can't combine option --config and --no-config
- failed to create meta-formatter: %w
- build walk options: %w
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/857041e7a0fbfcf5.
Report an issue: GitHub.