golangci/golangci-lint · error
build walk options: %w
Error message
build walk options: %w
What it means
fmt's preRunE builds goformat.NewRunnerOptions from the loaded config plus diff/diffColored/stdin flags. Failure is wrapped as "build walk options". This constructs file-walking/processing options (paths, exclusions, output modes); invalid combinations or values make fmt unable to set up its runner.
Source
Thrown at pkg/commands/fmt.go:107
return nil
}
func (c *fmtCommand) preRunE(_ *cobra.Command, _ []string) error {
if c.cfg.GetConfigDir() != "" && c.cfg.Version != "2" {
return fmt.Errorf("invalid version of the configuration: %q", c.cfg.Version)
}
metaFormatter, err := goformatters.NewMetaFormatter(c.log, &c.cfg.Formatters, &c.cfg.Run)
if err != nil {
return fmt.Errorf("failed to create meta-formatter: %w", err)
}
matcher := processors.NewGeneratedFileMatcher(c.cfg.Formatters.Exclusions.Generated)
opts, err := goformat.NewRunnerOptions(c.cfg, c.opts.diff, c.opts.diffColored, c.opts.stdin)
if err != nil {
return fmt.Errorf("build walk options: %w", err)
}
c.runner = goformat.NewRunner(c.log, metaFormatter, matcher, opts)
return nil
}
func (c *fmtCommand) execute(_ *cobra.Command, args []string) error {
paths := cleanArgs(args)
c.log.Infof("Formatting Go files...")
err := c.runner.Run(paths)
if err != nil {
return fmt.Errorf("failed to process files: %w", err)
}
return nilView on GitHub (pinned to ed7a235d2d)
Solutions
- Read the wrapped cause to see which option is invalid.
- Don't mix --stdin with path arguments or --diff; use one input mode at a time.
- Check --diff-colored is only used with --diff and your terminal supports it.
- Validate exclusion patterns in the config's formatters.exclusions section.
Example fix
// before golangci-lint fmt --stdin ./... // after golangci-lint fmt --stdin # stdin alone golangci-lint fmt ./... # or paths alone
Defensive patterns
Strategy: validation
Validate before calling
// ensure mutually exclusive flags aren't combined
if stdin && (len(paths) > 0 || diff) {
return fmt.Errorf("--stdin cannot be combined with paths or --diff")
}
if diffColored && !diff {
return fmt.Errorf("--diff-colored requires --diff")
} Try / catch
if err := fmtCmd.Run(); err != nil {
if strings.Contains(err.Error(), "build walk options") {
log.Fatalf("bad flag combination: %v", errors.Unwrap(err))
}
return err
} Prevention
- Use --stdin alone; pass paths as plain arguments otherwise.
- Only use --diff-colored together with --diff.
- Keep exclusion patterns in config valid globs; test them with a single file first.
When it happens
Trigger: Running `golangci-lint fmt` with incompatible flags/options: e.g. --stdin together with paths or --diff, invalid diff coloring option, or invalid exclusions/run settings affecting the walker.
Common situations: Combining `fmt --stdin` with directory arguments; using --diff and --stdin simultaneously; malformed exclusion patterns in `formatters.exclusions`.
Related errors
- failed to create meta-formatter: %w
- failed to process files: %w
- can't get enabled formatters: %w
- %s is not a formatter
- unable to open file %s: %w
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/3e7ad0e8012fdc75.
Report an issue: GitHub.