kubernetes/kops · error

snippet: %s, issue: %s

Error message

snippet: %s, issue: %s

What it means

includeSnippet executes a named template snippet against a context and wraps any ExecuteTemplate error with the snippet name for diagnosability. Unlike a syntax error, this failure happens during execution of the snippet — missing data keys, bad pipelines, or function errors. The snippet name in the message tells you exactly which nested include failed.

Source

Thrown at pkg/util/templater/templater.go:106

		}
		// @step: write the line to the buffer
		line := fmt.Sprintf("%"+fmt.Sprintf("%d", spacer)+"s%s", "", x)
		b.WriteString(line)

		// @check if we need a newline
		if i < length {
			b.WriteString("\n")
		}
	}

	return b.String()
}

// includeSnippet is responsible for including a snippet
func includeSnippet(tm *template.Template, name string, context map[string]interface{}) (string, error) {
	b := bytes.NewBufferString("")
	if err := tm.ExecuteTemplate(b, name, context); err != nil {
		return "", fmt.Errorf("snippet: %s, issue: %s", name, err)
	}

	return b.String(), nil
}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Read `snippet: <name>` in the message and open that snippet; the wrapped `issue` names the failing expression or missing key
  2. Add the missing context key or fix the snippet's expression to match the actual context type
  3. If you customized bundled snippets, diff them against upstream for the matching kOps version
  4. Test the snippet standalone with tmpl.ExecuteTemplate on a minimal context reproducing the data

Example fix

// before: snippet references context["KubernetesVersion"] but caller never set it
context := map[string]interface{}{"Region": "us-east-1"}
includeSnippet(tm, "networking", context) // snippet: networking, issue: map has no entry for key "KubernetesVersion"
// after
context := map[string]interface{}{"Region": "us-east-1", "KubernetesVersion": "1.28.0"}
includeSnippet(tm, "networking", context)
Defensive patterns

Strategy: validation

Validate before calling

keys := []string{"Region", "KubernetesVersion"}
for _, k := range keys {
    if _, ok := context[k]; !ok {
        return fmt.Errorf("context missing %q required by snippet %s", k, name)
    }
}

Try / catch

s, err := includeSnippet(tm, name, context)
if err != nil {
    return fmt.Errorf("rendering snippet %s: %w", name, err) // name already embedded in the wrapped error
}

Prevention

When it happens

Trigger: tm.ExecuteTemplate(b, name, context) returns an error while rendering the snippet named `name` — e.g. the snippet references a key absent from context, or a pipeline type mismatch (executing a field of an int as a map).

Common situations: A snippet template expects a context key (e.g. a region, zone, or config value) that the caller did not set; snippet files edited/customized with incompatible expressions; version mismatch between snippet templates and the code supplying context.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/ac02746f294a4875. Report an issue: GitHub.