{"record":{"id":"0bb8285c84c89883","repo":"navidrome/navidrome","slug":"reading-go-mod-template-w","errorCode":null,"errorMessage":"reading go.mod template: %w","messagePattern":"reading go\\.mod template: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/cmd/ndpgen/internal/generator.go","lineNumber":322,"sourceCode":"\t\tServices []Service\n\t}{\n\t\tPackage:  pkgName,\n\t\tServices: services,\n\t}\n\n\tvar buf bytes.Buffer\n\tif err := tmpl.Execute(&buf, data); err != nil {\n\t\treturn nil, fmt.Errorf(\"executing template: %w\", err)\n\t}\n\n\treturn buf.Bytes(), nil\n}\n\n// GenerateGoMod generates the go.mod file for the Go client library.\nfunc GenerateGoMod() ([]byte, error) {\n\ttmplContent, err := templatesFS.ReadFile(\"templates/go.mod.tmpl\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"reading go.mod template: %w\", err)\n\t}\n\treturn tmplContent, nil\n}\n\n// capabilityTemplateData holds data for capability template execution.\ntype capabilityTemplateData struct {\n\tPackage    string\n\tCapability Capability\n}\n\n// capabilityFuncMap returns template functions for capability code generation.\nfunc capabilityFuncMap(cap Capability) template.FuncMap {\n\treturn template.FuncMap{\n\t\t\"formatDoc\":         formatDoc,\n\t\t\"indent\":            indentText,\n\t\t\"agentName\":         capabilityAgentName,\n\t\t\"providerInterface\": func(e Export) string { return e.ProviderInterfaceName() },\n\t\t\"implVar\":           func(e Export) string { return e.ImplVarName() },","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/navidrome/navidrome/blob/4ed7494a3293a9e9e647897ebfb9be327efd981b/plugins/cmd/ndpgen/internal/generator.go#L304-L340","documentation":"GenerateGoMod reads templates/go.mod.tmpl from the embedded templates FS (templatesFS). If that embedded read fails, the error is wrapped as 'reading go.mod template: %w'. Since the file is embedded at build time, a failure means the template is missing from the embed directive or the embed.FS was not populated — a build/packaging problem, not a runtime filesystem issue.","triggerScenarios":"Calling GenerateGoMod (via generateGoModFile) when templates/go.mod.tmpl does not exist under the embedded //go:embed templates path, or the embed pattern excludes it (e.g. .tmpl files ignored by build constraints or embed globs).","commonSituations":"Template file deleted or renamed (go.mod.tmpl -> go.mod.template) without updating //go:embed; building from a partial checkout/trimmed source archive; packaging tools (upx, custom builders) stripping embedded assets; wrong working copy committed to CI.","solutions":["Verify templates/go.mod.tmpl exists in plugins/cmd/ndpgen/internal/templates and is covered by the //go:embed pattern.","Run go build ./... and regenerate; embed.FS is validated at compile time, so build errors point at the missing file.","Check .gitignore / release packaging isn't excluding *.tmpl files from the source used to build.","Restore the file from git history if it was renamed or removed: git checkout -- plugins/cmd/ndpgen/internal/templates/go.mod.tmpl"],"exampleFix":"// before: embed pattern misses tmpl files\n//go:embed templates/*.go\nvar templatesFS embed.FS\n// after\n//go:embed templates\nvar templatesFS embed.FS","handlingStrategy":"fallback","validationCode":"// compile-time guard next to the embed directive\n//go:embed templates\nvar templatesFS embed.FS\n// runtime pre-check\nif _, err := templatesFS.ReadFile(\"templates/go.mod.tmpl\"); err != nil {\n    panic(\"go.mod.tmpl missing from embedded templates: \" + err.Error())\n}","typeGuard":null,"tryCatchPattern":"gomod, err := generator.GenerateGoMod()\nif err != nil {\n    if strings.Contains(err.Error(), \"reading go.mod template\") {\n        log.Fatalf(\"embedded go.mod.tmpl missing — rebuild ndpgen from a complete checkout: %v\", err)\n    }\n    return err\n}","preventionTips":["Embed the whole templates directory rather than per-file globs.","Add a test asserting every path passed to templatesFS.ReadFile exists in the embed.FS.","Don't .gitignore *.tmpl; audit packaging scripts for asset stripping.","Build from a clean, complete checkout in CI."],"tags":["go","embed","code-generation","missing-file"],"backgroundTag":"missing-embedded-template","analyzedSha":"4ed7494a3293a9e9e647897ebfb9be327efd981b","analyzedAt":"2026-09-01T05:03:05.018Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}