{"record":{"id":"01f8fb4bfd16f69c","repo":"golangci/golangci-lint","slug":"parsing-s-w","errorCode":null,"errorMessage":"parsing %s: %w","messagePattern":"parsing (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/internal/migrate/cloner/cloner.go","lineNumber":58,"sourceCode":"\t\tlog.Fatalf(\"Processing package error: %v\", err)\n\t}\n}\n\nfunc processPackage(srcDir, dstDir string) error {\n\treturn filepath.Walk(srcDir, func(srcPath string, _ os.FileInfo, err error) error {\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif skipFile(srcPath) {\n\t\t\treturn nil\n\t\t}\n\n\t\tfset := token.NewFileSet()\n\n\t\tfile, err := parser.ParseFile(fset, srcPath, nil, parser.AllErrors)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"parsing %s: %w\", srcPath, err)\n\t\t}\n\n\t\tprocessFile(file)\n\n\t\treturn writeNewFile(fset, file, srcPath, dstDir)\n\t})\n}\n\nfunc skipFile(path string) bool {\n\tif !strings.HasSuffix(path, \".go\") || strings.HasSuffix(path, \"_test.go\") {\n\t\treturn true\n\t}\n\n\tswitch filepath.Base(path) {\n\tcase \"base_loader.go\", \"loader.go\":\n\t\treturn true\n\tdefault:\n\t\treturn false","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/internal/migrate/cloner/cloner.go#L40-L76","documentation":"The cloner walks ./pkg/config and parses each .go file with parser.ParseFile using parser.AllErrors. The 'parsing %s: %w' wrap means the source file could not be parsed into a valid Go AST. Because AllErrors is set, even minor syntax problems cause a hard failure and abort the whole filepath.Walk.","triggerScenarios":"Running the cloner tool when a file under pkg/config (excluding _test.go, base_loader.go, loader.go) contains Go syntax that does not parse — e.g. the file uses syntax from a newer Go version than the toolchain running the tool, or the file is truncated/corrupted.","commonSituations":"Running the migration tool with an older Go toolchain than the one used to write pkg/config (newer language features fail to parse), a mid-edit/broken file in the source tree, or generated files with syntax errors left in the directory.","solutions":["Read the wrapped go/parser error — it names the exact file and line/column of the syntax problem","Check the file at that position for a genuine syntax error or truncated content","Ensure the Go toolchain running the cloner is at least as new as the go directive in go.mod (newer syntax won't parse on older tools)","Exclude any intentionally broken/generated files via skipFile in cloner.go"],"exampleFix":"// before (cloner run with Go 1.20 against code using generics ranges)\nfor i := range 10 { ... } // parse error on old toolchain\n// after: run with the toolchain matching go.mod, e.g.\ngo1.22 run ./pkg/commands/internal/migrate/cloner","handlingStrategy":"validation","validationCode":"// pre-check files compile-parse with the current toolchain before running the cloner\nif err := exec.Command(\"go\", \"vet\", srcDir).Run(); err != nil {\n    log.Fatalf(\"pkg/config does not parse/vet with current toolchain: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"err := processPackage(srcDir, dstDir)\nif err != nil {\n    var perr scanner.ErrorList\n    if errors.As(err, &perr) {\n        for _, e := range perr {\n            log.Printf(\"parse problem: %v\", e)\n        }\n    }\n    log.Fatalf(\"Processing package error: %v\", err)\n}","preventionTips":["Run the cloner with the same Go version as the module's go directive","Commit only syntactically valid files; never run the tool mid-edit","Extend skipFile to exclude known-broken or non-Go-standard files","Run gofmt/go vet on pkg/config before each migration run"],"tags":["go","ast-parsing","syntax-error","code-generation"],"backgroundTag":"go-parse-error","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}