{"record":{"id":"0f11ec878e98ffc2","repo":"googleapis/mcp-toolbox","slug":"error-parsing-markdown-template-w","errorCode":null,"errorMessage":"error parsing markdown template: %w","messagePattern":"error parsing markdown template: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/internal/skills/generator.go","lineNumber":109,"sourceCode":"\t\t}\n\n\t\ttoolsData = append(toolsData, toolTemplateData{\n\t\t\tName:             name,\n\t\t\tDescription:      manifest.Description,\n\t\t\tParametersSchema: parametersSchema,\n\t\t})\n\t}\n\n\tdata := skillTemplateData{\n\t\tSkillName:        skillName,\n\t\tSkillDescription: skillDescription,\n\t\tAdditionalNotes:  additionalNotes,\n\t\tTools:            toolsData,\n\t}\n\n\ttmpl, err := template.New(\"markdown\").Parse(skillTemplate)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error parsing markdown template: %w\", err)\n\t}\n\n\tvar buf strings.Builder\n\tif err := tmpl.Execute(&buf, data); err != nil {\n\t\treturn \"\", fmt.Errorf(\"error executing markdown template: %w\", err)\n\t}\n\n\treturn buf.String(), nil\n}\n\nconst nodeScriptTemplate = `#!/usr/bin/env node\n{{if .LicenseHeader}}\n{{.LicenseHeader}}\n{{end}}\nconst { spawn, execSync } = require('child_process');\nconst path = require('path');\nconst fs = require('fs');\nconst os = require('os');","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/cmd/internal/skills/generator.go#L91-L127","documentation":"`generateSkillMarkdown` throws \"error parsing markdown template: %w\" when Go's `text/template` cannot parse the embedded `skillTemplate` string (`template.New(\"markdown\").Parse(skillTemplate)` fails). Because the template is compiled into the binary, this almost always indicates a bug in the shipped template text (e.g. malformed `{{...}}` actions) rather than anything the user configured. The wrapped error from text/template names the line and syntax problem.","triggerScenarios":"Calling `generateSkillMarkdown` (via `run` or the unit test `TestGenerateSkillMarkdown`) with a `skillTemplate` containing invalid template syntax such as unbalanced `{{`/`}}`, unknown functions, or an unterminated action.","commonSituations":"A developer edited the embedded `skillTemplate` constant in `cmd/internal/skills/generator.go` and introduced a syntax error; a custom template passed through a fork/patch is malformed; Go version differences in template parsing behavior.","solutions":["Read the wrapped text/template error — it pinpoints the offending line/column in the template","Check `skillTemplate` in cmd/internal/skills/generator.go for unbalanced `{{ }}`, bad pipelines, or undefined functions","Rebuild the binary so the embedded template matches the source (`go build -o toolbox`)","If customizing, test the template with `TestGenerateSkillMarkdown` before shipping"],"exampleFix":"// before: malformed action in skillTemplate\n// {{ if .Tools }}...{{ end\n// after: closed action\n// {{ if .Tools }}...{{ end }}","handlingStrategy":"try-catch","validationCode":"// Validate template syntax at startup/test time\nfunc validateTemplate(t string) error {\n\t_, err := template.New(\"markdown\").Parse(t)\n\treturn err\n}\n// call in an init() or unit test so bad templates fail fast","typeGuard":null,"tryCatchPattern":"tmpl, err := template.New(\"markdown\").Parse(skillTemplate)\nif err != nil {\n\treturn \"\", fmt.Errorf(\"error parsing markdown template: %w\", err)\n}","preventionTips":["Add a unit test that parses every embedded template at package init","Run `go test ./cmd/internal/skills/...` after editing generator.go templates","Keep template actions balanced; escape literal `{{` in generated content","Rebuild the binary after changing embedded templates (go:embed is compile-time)"],"tags":["go","template","text-template","codegen"],"backgroundTag":"template-parse-error","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}