golangci/golangci-lint · error
forbidigo linter failed on file %q: %w
Error message
forbidigo linter failed on file %q: %w
What it means
After successfully creating the forbidigo linter, runForbidigo runs it per AST file with RunWithConfig. If forbidigo itself errors while matching a file, the error is wrapped as 'forbidigo linter failed on file %q'. This is an internal failure of the linter on a specific file, not a rule violation.
Source
Thrown at pkg/golinters/forbidigo/forbidigo.go:73
forbid, err := forbidigo.NewLinter(patterns, options...)
if err != nil {
return fmt.Errorf("failed to create linter %q: %w", linterName, err)
}
for _, file := range pass.Files {
runConfig := forbidigo.RunConfig{
Fset: pass.Fset,
DebugLog: logutils.Debug(logutils.DebugKeyForbidigo),
}
if settings.AnalyzeTypes {
runConfig.TypesInfo = pass.TypesInfo
}
hints, err := forbid.RunWithConfig(runConfig, file)
if err != nil {
return fmt.Errorf("forbidigo linter failed on file %q: %w", file.Name.String(), err)
}
for _, hint := range hints {
pass.Report(analysis.Diagnostic{
Pos: hint.Pos(),
Message: hint.Details(),
})
}
}
return nil
}
View on GitHub (pinned to ed7a235d2d)
Solutions
- Disable settings.forbidigo.analyze-types and re-run to isolate the failure
- Fix the package so type checking completes (resolve cgo/build-tag/generated-file issues for the named file)
- Upgrade or pin golangci-lint so golangci-lint's forbidigo wrapper matches the bundled forbidigo API
- Exclude the problematic file via issues.exclude-files/exclude-dirs and report upstream if it persists
Example fix
# before
linters:
settings:
forbidigo:
analyze-types: true
# after
linters:
settings:
forbidigo:
analyze-types: false Defensive patterns
Strategy: try-catch
Validate before calling
// If using analyze-types, ensure packages type-check first:
for _, pkg := range pkgs {
for _, e := range pkg.Errors {
return fmt.Errorf("package %s must type-check before forbidigo analyze-types: %v", pkg.PkgPath, e)
}
} Try / catch
if err := golangci.Run(); err != nil {
if strings.Contains(err.Error(), "forbidigo linter failed on file") {
file := extractQuoted(err) // e.g. via regexp "on file \"([^\"]+)\""
log.Warnf("forbidigo failed on %s; retry with analyze-types: false or exclude the file", file)
return retryWithoutAnalyzeTypes()
}
return err
} Prevention
- Only enable analyze-types when the whole package type-checks cleanly
- Exclude cgo/generated files that break type info
- Pin golangci-lint so forbidigo wrapper and library versions match
When it happens
Trigger: forbid.RunWithConfig(runConfig, file) returns an error for one file — e.g. with settings.analyze-types: true, type information is missing or inconsistent in runConfig, or the file node/config combination is invalid.
Common situations: Enabling analyze-types on a run where TypesInfo wasn't fully populated (generated/cgo files, malformed packages), or forbidigo version mismatches where RunConfig fields differ from what golangci-lint passes.
Related errors
- failed to create linter %q: %w
- the configuration contains invalid elements
- unsupported configuration format
- the configuration contains invalid elements
- parallel golangci-lint is running
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/5b89d145537c0cfe.
Report an issue: GitHub.