{"record":{"id":"467e69eefdc699d8","repo":"golangci/golangci-lint","slug":"gci-creating-formatter-w","errorCode":null,"errorMessage":"gci: creating formatter: %w","messagePattern":"gci: creating formatter: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/goformatters/meta_formatter.go","lineNumber":53,"sourceCode":"\t}\n\n\tif slices.Contains(cfg.Enable, gofumpt.Name) {\n\t\tm.formatters = append(m.formatters, gofumpt.New(&cfg.Settings.GoFumpt, runCfg.Go))\n\t}\n\n\tif slices.Contains(cfg.Enable, goimports.Name) {\n\t\tm.formatters = append(m.formatters, goimports.New(&cfg.Settings.GoImports))\n\t}\n\n\tif slices.Contains(cfg.Enable, swaggo.Name) {\n\t\tm.formatters = append(m.formatters, swaggo.New())\n\t}\n\n\t// gci is a last because the only goal of gci is to handle imports.\n\tif slices.Contains(cfg.Enable, gci.Name) {\n\t\tformatter, err := gci.New(&cfg.Settings.Gci)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"gci: creating formatter: %w\", err)\n\t\t}\n\n\t\tm.formatters = append(m.formatters, formatter)\n\t}\n\n\t// golines calls `format.Source()` internally so no need to format after it.\n\tif slices.Contains(cfg.Enable, golines.Name) {\n\t\tm.formatters = append(m.formatters, golines.New(&cfg.Settings.GoLines))\n\t}\n\n\treturn m, nil\n}\n\nfunc (m *MetaFormatter) Format(filename string, src []byte) []byte {\n\tif len(m.formatters) == 0 {\n\t\tdata, err := format.Source(src)\n\t\tif err != nil {\n\t\t\tm.log.Warnf(\"(fmt) formatting file %s: %v\", filename, err)","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/goformatters/meta_formatter.go#L35-L71","documentation":"When gci is in the enabled formatters list, NewMetaFormatter constructs the gci formatter from its settings; if gci.New fails, the error is wrapped as 'gci: creating formatter: %w'. The root cause is an invalid gci configuration (bad sections or unparseable options), not golangci-lint itself.","triggerScenarios":"formatters.enable contains 'gci' AND settings.gci contains invalid values, e.g. malformed custom sections like 'prefix(github.com' (unbalanced paren) or an unknown section keyword, causing gci.New to return an error.","commonSituations":"Copying gci sections from another project with wrong syntax, forgetting the 'standard' or 'default' section, typos like 'PrefiX(...)', or gci option shape changes after upgrading golangci-lint's bundled gci.","solutions":["Fix settings.gci.sections: each entry must be 'standard', 'default', 'prefix(module/path)', 'blank-imports', etc.","Verify prefix module paths are valid and parentheses are balanced","Test the gci config standalone: gci diff --section standard .","Check the gci version bundled with your golangci-lint for syntax changes and adjust"],"exampleFix":"# before\nformatters:\n  enable: [gci]\n  settings:\n    gci:\n      sections:\n        - prefix(github.com/myorg\n# after\nformatters:\n  enable: [gci]\n  settings:\n    gci:\n      sections:\n        - standard\n        - default\n        - prefix(github.com/myorg)","handlingStrategy":"validation","validationCode":"import \"github.com/maratori/gci\"\nfor _, s := range cfg.LintersSettings.Gci.Sections {\n    if s != \"standard\" && s != \"default\" && s != \"blank-imports\" && s != \"comment\" && s != \"cgo\" && !strings.HasPrefix(s, \"prefix(\") {\n        return fmt.Errorf(\"invalid gci section %q\", s)\n    }\n    if strings.HasPrefix(s, \"prefix(\") && !strings.HasSuffix(s, \")\") {\n        return fmt.Errorf(\"malformed gci prefix section %q\", s)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := golangci.Run(); err != nil {\n    if strings.Contains(err.Error(), \"gci: creating formatter\") {\n        fmt.Fprintln(os.Stderr, \"check linters-settings.gci sections syntax (standard|default|prefix(mod))\")\n        os.Exit(1)\n    }\n    return err\n}","preventionTips":["Test gci config standalone with 'gci diff --section ...' before adding to .golangci.yml","Keep sections as standard, default, then prefix(...) entries","Re-check gci section syntax when upgrading golangci-lint"],"tags":["golangci-lint","configuration","gci","imports"],"backgroundTag":"invalid-gci-configuration","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}