{"record":{"id":"20b28e8e97b7b579","repo":"golangci/golangci-lint","slug":"failed-to-parse-file-w","errorCode":null,"errorMessage":"failed to parse file: %w","messagePattern":"failed to parse file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/result/processors/exclusion_generated_file_matcher.go","lineNumber":53,"sourceCode":"\n\tmode string\n}\n\nfunc NewGeneratedFileMatcher(mode string) *GeneratedFileMatcher {\n\treturn &GeneratedFileMatcher{\n\t\tdebugf: logutils.Debug(logutils.DebugKeyGeneratedFileFilter),\n\t\tmode:   mode,\n\t}\n}\n\nfunc (p *GeneratedFileMatcher) IsGeneratedFile(filepath string, src any) (bool, error) {\n\tif p.mode == config.GeneratedModeDisable {\n\t\treturn false, nil\n\t}\n\n\tfile, err := parser.ParseFile(token.NewFileSet(), filepath, src, parser.PackageClauseOnly|parser.ParseComments)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"failed to parse file: %w\", err)\n\t}\n\n\tif p.mode == config.GeneratedModeStrict {\n\t\treturn isGeneratedFileStrict(file), nil\n\t}\n\n\tdoc := getComments(file)\n\n\treturn p.isGeneratedFileLax(doc), nil\n}\n\n// isGeneratedFileLax reports whether the source file is generated code.\n// The function uses a bit laxer rules than isGeneratedFileStrict to match more generated code.\n// See https://github.com/golangci/golangci-lint/issues/48 and https://github.com/golangci/golangci-lint/issues/72.\nfunc (p *GeneratedFileMatcher) isGeneratedFileLax(doc string) bool {\n\tmarkers := []string{genCodeGenerated, genDoNotEdit, genAutoFile, genSwaggerCodegen}\n\n\tdoc = strings.ToLower(doc)","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/result/processors/exclusion_generated_file_matcher.go#L35-L71","documentation":"The generated-file matcher parses each candidate file with go/parser (package clause only, with comments) to find the '// Code generated ...' doc comment. If the file is not valid Go, ParseFile fails and this wrapped error is returned. golangci-lint cannot decide generated status for a file it cannot parse.","triggerScenarios":"IsGeneratedFile is called (from shouldPassIssue, process, or formatStdIn) with filepath whose contents are not parseable Go — invalid syntax, empty/corrupt file, or a non-Go file fed to the processor.","commonSituations":"Broken generated code committed to the repo; template-rendered .go files with placeholder syntax errors; mixing file extensions (e.g. linting .go files that contain JSON); tool version mismatch producing partially-written files during codegen.","solutions":["Fix the syntax error in the flagged file (run gofmt/go vet locally to locate it)","Regenerate the file with its code generator at the correct version","Ensure only valid .go files are linted (adjust skip-files/exclusions)","If the file is intentionally not Go, rename its extension"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Go: pre-check that the file is parseable Go before treating it as generated-candidate\nfset := token.NewFileSet()\nif _, err := parser.ParseFile(fset, path, nil, parser.PackageClauseOnly|parser.ParseComments); err != nil {\n    return fmt.Errorf(\"not valid Go, skip generated check: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"gen, err := m.IsGeneratedFile(path, nil)\nif err != nil {\n    var perr scanner.ErrorList\n    if errors.As(err, &perr) { log.Printf(\"parse errors in %s: %v\", path, perr) }\n    return err\n}","preventionTips":["Run gofmt/go build in CI before linting to catch syntax errors early","Pin code generator versions so output is always valid","Never commit partially generated .go files"],"tags":["go-ast","parser","generated-files"],"backgroundTag":"go-parse-error","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}