{"record":{"id":"69413e79ad1bf7e7","repo":"golangci/golangci-lint","slug":"parse-template-w","errorCode":null,"errorMessage":"parse template: %w","messagePattern":"parse template: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/internal/imports.go","lineNumber":48,"sourceCode":"\tsource, err := generateImports(b.cfg)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"generate imports: %w\", err)\n\t}\n\n\tb.log.Infof(\"generated imports info %s:\\n%s\\n\", importsDest, source)\n\n\terr = os.WriteFile(filepath.Clean(importsDest), source, info.Mode())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"write file %s: %w\", importsDest, err)\n\t}\n\n\treturn nil\n}\n\nfunc generateImports(cfg *Configuration) ([]byte, error) {\n\timpTmpl, err := template.New(\"plugins.go\").Parse(importsTemplate)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"parse template: %w\", err)\n\t}\n\n\tvar imps []string\n\tfor _, plugin := range cfg.Plugins {\n\t\timps = append(imps, plugin.Import)\n\t}\n\n\tbuf := &bytes.Buffer{}\n\n\terr = impTmpl.Execute(buf, map[string]any{\"Imports\": imps})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"execute template: %w\", err)\n\t}\n\n\tsource, err := format.Source(buf.Bytes())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"format source: %w\", err)\n\t}","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/internal/imports.go#L30-L66","documentation":"generateImports parses the embedded importsTemplate with template.New(\"plugins.go\").Parse. If the template text is syntactically invalid, it returns 'parse template: %w'. Since the template ships inside the binary, this usually means the source tree was edited or a template action is malformed.","triggerScenarios":"template.Parse fails on importsTemplate — malformed Go template actions ({{...}}), stray braces, or a locally edited template string in pkg/commands/internal/imports.go.","commonSituations":"Hand-editing importsTemplate and breaking syntax; unresolved merge-conflict markers inside the template literal; backtick/quoting issues when patching; copy-paste introducing invalid actions.","solutions":["Restore the original importsTemplate from upstream golangci-lint for your version","Fix the template syntax at pkg/commands/internal/imports.go (the parse error names line/column)","Remove any merge-conflict markers inside the template literal","Validate the template with a small Go snippet (template.New(...).Parse) before rebuilding"],"exampleFix":"// before\nimportsTemplate = `package main {{ .BadAction `\n// after\nimportsTemplate = `package main\n\nimport (\n{{ range .Imports }}\t_ \"{{ . }}\"\n{{ end }})\n`","handlingStrategy":"validation","validationCode":"if _, err := template.New(\"plugins.go\").Parse(importsTemplate); err != nil {\n\treturn fmt.Errorf(\"importsTemplate is invalid: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"_, err := generateImports(cfg)\nif err != nil && strings.HasPrefix(err.Error(), \"parse template:\") {\n\treturn fmt.Errorf(\"built-in template corrupted; restore pkg/commands/internal/imports.go from upstream: %w\", err)\n}","preventionTips":["Do not hand-edit importsTemplate without re-testing Parse","Resolve merge conflicts carefully in files containing template literals","Pin the golangci-lint source version when patching","Add a unit test that parses all embedded templates"],"tags":["go","template","build"],"backgroundTag":"template-parse-error","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}