{"record":{"id":"b00bffebb399b916","repo":"googleapis/mcp-toolbox","slug":"error-executing-script-template-w","errorCode":null,"errorMessage":"error executing script template: %w","messagePattern":"error executing script template: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/internal/skills/generator.go","lineNumber":273,"sourceCode":"// (using a generated config) and arguments to execute the specific tool.\nfunc generateScriptContent(name string, configArgs string, licenseHeader string, mode string, version string, optionalVars []string) (string, error) {\n\tdata := scriptData{\n\t\tName:           name,\n\t\tConfigArgs:     configArgs,\n\t\tLicenseHeader:  licenseHeader,\n\t\tInvocationMode: mode,\n\t\tToolboxVersion: version,\n\t\tOptionalVars:   optionalVars,\n\t}\n\n\ttmpl, err := template.New(\"script\").Parse(nodeScriptTemplate)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error parsing script 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 script template: %w\", err)\n\t}\n\n\treturn buf.String(), nil\n}\n\n// formatParameters converts a list of parameter manifests into a formatted JSON schema string.\n// This schema is used in the skill documentation to describe the input parameters for a tool.\nfunc formatParameters(params []parameters.ParameterManifest, envVars map[string]string) (string, error) {\n\tif len(params) == 0 {\n\t\treturn \"\", nil\n\t}\n\n\tvar sb strings.Builder\n\tsb.WriteString(\"#### Parameters\\n\\n\")\n\tsb.WriteString(\"| Name | Type | Description | Required | Default |\\n\")\n\tsb.WriteString(\"| :--- | :--- | :--- | :--- | :--- |\\n\")\n\n\tfor _, p := range params {","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/cmd/internal/skills/generator.go#L255-L291","documentation":"`generateScriptContent` throws \"error executing script template: %w\" when the parsed `nodeScriptTemplate` fails during `tmpl.Execute(&buf, data)` while rendering the Node wrapper script with the tool data (name, parameters, toolbox version, optional vars). Parse succeeded; rendering against the provided `data` struct failed, typically because a template action dereferences a missing/nil value or a method returns an error.","triggerScenarios":"`tmpl.Execute(&buf, data)` is called with the script data struct and a field/method used in `nodeScriptTemplate` fails — e.g. ranging over a nil parameters slice, calling a method that returns an error, or a field renamed in the data struct that the template still references.","commonSituations":"A tool manifest with nil/empty parameters fed into the template after a refactor changed the data struct fields; template actions reference fields removed from the script data struct; version/optionalVars fields unset where the template assumes values.","solutions":["Read the wrapped execution error — it names the failing template node and line","Verify every field referenced in `nodeScriptTemplate` exists on the script data struct and is non-nil where used","Add `{{ if }}` guards around optional fields (optionalVars, parameters) in the template","Reproduce with the failing tool's manifest in a unit test for generateScriptContent"],"exampleFix":"// before (template): {{ range .OptionalVars }}{{ . }}{{ end }} on nil slice\n// after (template): {{ if .OptionalVars }}{{ range .OptionalVars }}{{ . }}{{ end }}{{ end }}","handlingStrategy":"try-catch","validationCode":"// Normalize inputs before rendering\nif optionalVars == nil { optionalVars = map[string]string{} }\nif params == nil { params = []map[string]any{} }","typeGuard":null,"tryCatchPattern":"var buf strings.Builder\nif err := tmpl.Execute(&buf, data); err != nil {\n\treturn \"\", fmt.Errorf(\"error executing script template: %w\", err)\n}","preventionTips":["Guard optional fields (optionalVars, parameters) with `{{ if }}` in the template","Keep nodeScriptTemplate field references aligned with the data struct definition","Test generateScriptContent with manifests missing optional fields","Inspect the wrapped error's template line to locate the failing action"],"tags":["go","template","text-template","codegen","nodejs"],"backgroundTag":"template-execution-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"}