golangci/golangci-lint · error

parsing %s: %w

Error message

parsing %s: %w

What it means

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.

Source

Thrown at pkg/commands/internal/migrate/cloner/cloner.go:58

		log.Fatalf("Processing package error: %v", err)
	}
}

func processPackage(srcDir, dstDir string) error {
	return filepath.Walk(srcDir, func(srcPath string, _ os.FileInfo, err error) error {
		if err != nil {
			return err
		}

		if skipFile(srcPath) {
			return nil
		}

		fset := token.NewFileSet()

		file, err := parser.ParseFile(fset, srcPath, nil, parser.AllErrors)
		if err != nil {
			return fmt.Errorf("parsing %s: %w", srcPath, err)
		}

		processFile(file)

		return writeNewFile(fset, file, srcPath, dstDir)
	})
}

func skipFile(path string) bool {
	if !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") {
		return true
	}

	switch filepath.Base(path) {
	case "base_loader.go", "loader.go":
		return true
	default:
		return false

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Read the wrapped go/parser error — it names the exact file and line/column of the syntax problem
  2. Check the file at that position for a genuine syntax error or truncated content
  3. 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)
  4. Exclude any intentionally broken/generated files via skipFile in cloner.go

Example fix

// before (cloner run with Go 1.20 against code using generics ranges)
for i := range 10 { ... } // parse error on old toolchain
// after: run with the toolchain matching go.mod, e.g.
go1.22 run ./pkg/commands/internal/migrate/cloner
Defensive patterns

Strategy: validation

Validate before calling

// pre-check files compile-parse with the current toolchain before running the cloner
if err := exec.Command("go", "vet", srcDir).Run(); err != nil {
    log.Fatalf("pkg/config does not parse/vet with current toolchain: %v", err)
}

Try / catch

err := processPackage(srcDir, dstDir)
if err != nil {
    var perr scanner.ErrorList
    if errors.As(err, &perr) {
        for _, e := range perr {
            log.Printf("parse problem: %v", e)
        }
    }
    log.Fatalf("Processing package error: %v", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02). Data as JSON: /api/errors/01f8fb4bfd16f69c. Report an issue: GitHub.