googleapis/mcp-toolbox · error

error executing markdown template: %w

Error message

error executing markdown template: %w

What it means

`generateSkillMarkdown` throws "error executing markdown template: %w" when the parsed template fails during `tmpl.Execute(&buf, data)` — i.e., the data injected into the template triggered an execution error (e.g., calling a method/field on a nil value, a pipeline returning an error, or a write failure to the strings.Builder). Parsing succeeded; rendering with the given `data` struct did not.

Source

Thrown at cmd/internal/skills/generator.go:114

			ParametersSchema: parametersSchema,
		})
	}

	data := skillTemplateData{
		SkillName:        skillName,
		SkillDescription: skillDescription,
		AdditionalNotes:  additionalNotes,
		Tools:            toolsData,
	}

	tmpl, err := template.New("markdown").Parse(skillTemplate)
	if err != nil {
		return "", fmt.Errorf("error parsing markdown template: %w", err)
	}

	var buf strings.Builder
	if err := tmpl.Execute(&buf, data); err != nil {
		return "", fmt.Errorf("error executing markdown template: %w", err)
	}

	return buf.String(), nil
}

const nodeScriptTemplate = `#!/usr/bin/env node
{{if .LicenseHeader}}
{{.LicenseHeader}}
{{end}}
const { spawn, execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const os = require('os');

const toolName = "{{.Name}}";
const configArgs = [{{.ConfigArgs}}];
{{if .OptionalVars}}
const OPTIONAL_VARS_TO_OMIT_IF_EMPTY = [

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Read the wrapped execution error — text/template reports the failing template node and line
  2. Check that all fields referenced in `skillTemplate` exist on the data struct and are non-nil where used
  3. Guard template actions with `{{ if ... }}` before ranging/dereferencing possibly-empty values
  4. Re-run `TestGenerateSkillMarkdown` with the failing data to reproduce locally

Example fix

// before (template): {{ range .Tools }}...{{ end }} panics/execs nil
// after (template): {{ if .Tools }}{{ range .Tools }}...{{ end }}{{ end }}
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure data fields the template ranges over are non-nil before executing
if data.Tools == nil { data.Tools = []toolsData{} }
if err := validateTemplateFields(data); err != nil { return "", err }

Try / catch

var buf strings.Builder
if err := tmpl.Execute(&buf, data); err != nil {
	return "", fmt.Errorf("error executing markdown template: %w", err)
}

Prevention

When it happens

Trigger: `tmpl.Execute` is called with the skill data struct (name, description, additionalNotes, toolsData) and a field access or method invoked inside `skillTemplate` fails at runtime, or the writer returns an error.

Common situations: Nil map/pointer fields in the data struct dereferenced by template actions like `{{ range .Tools }}` or `{{ .SomeField.Method }}`; a template function changed signature after a refactor; out-of-memory/write errors are rare but possible.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/dc8092c698f11a8c. Report an issue: GitHub.