{"record":{"id":"857041e7a0fbfcf5","repo":"golangci/golangci-lint","slug":"error-while-running-s-w","errorCode":null,"errorMessage":"error while running %s: %w","messagePattern":"error while running (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/goformatters/analyzer.go","lineNumber":36,"sourceCode":"func NewAnalyzer(logger logutils.Log, doc string, formatter Formatter) *analysis.Analyzer {\n\treturn &analysis.Analyzer{\n\t\tName: formatter.Name(),\n\t\tDoc:  doc,\n\t\tRun: func(pass *analysis.Pass) (any, error) {\n\t\t\tfor _, file := range pass.Files {\n\t\t\t\tposition, isGoFile := goanalysis.GetGoFilePosition(pass, file)\n\t\t\t\tif !isGoFile {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tinput, err := os.ReadFile(position.Filename)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"unable to open file %s: %w\", position.Filename, err)\n\t\t\t\t}\n\n\t\t\t\toutput, err := formatter.Format(position.Filename, input)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"error while running %s: %w\", formatter.Name(), err)\n\t\t\t\t}\n\n\t\t\t\tif !bytes.Equal(input, output) {\n\t\t\t\t\tnewName := filepath.ToSlash(position.Filename)\n\t\t\t\t\toldName := newName + \".orig\"\n\n\t\t\t\t\tpatch := diff.Diff(oldName, input, newName, output)\n\n\t\t\t\t\terr = internal.ExtractDiagnosticFromPatch(pass, file, patch, logger)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, fmt.Errorf(\"can't extract issues from %s diff output %q: %w\", formatter.Name(), patch, err)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn nil, nil\n\t\t},\n\t}","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/goformatters/analyzer.go#L18-L54","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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"],"exampleFix":"# before: formatter option typo\nformatters:\n  settings:\n    goimports:\n      local-prefixes: [unclosed\n# after\nformatters:\n  settings:\n    goimports:\n      local-prefixes:\n        - github.com/my/org","handlingStrategy":"validation","validationCode":"// ensure the file parses before formatter runs\nif _, err := parser.ParseFile(fset, path, nil, parser.AllErrors); err != nil {\n    log.Fatalf(\"invalid Go source: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"// identify which formatter failed from the wrapped message\nif strings.Contains(err.Error(), \"error while running gofumpt\") {\n    // fix file syntax or gofumpt settings\n}","preventionTips":["Keep formatter versions pinned and updated","Validate formatter settings in .golangci.yml","Exclude intentionally-invalid placeholder files"],"tags":["golangci-lint","formatters","configuration"],"backgroundTag":"formatter-run-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}