kubernetes/kops · error

unable to expand the snippets: %s, error: %s

Error message

unable to expand the snippets: %s, error: %s

What it means

Returned by RunToolBoxTemplate when expandFiles() fails on one of the --snippets-path entries. Like the template path, the snippet path is ~-expanded then glob-expanded; failure means the snippet path/glob is invalid, matches nothing, or cannot be read. It wraps the underlying filesystem error with the offending path.

Source

Thrown at cmd/kops/toolbox_template.go:156

		}
		return nil
	}

	// @step: expand the list of templates into a list of files to render
	var templates []string
	for _, x := range options.templatePath {
		list, err := expandFiles(utils.ExpandPath(x))
		if err != nil {
			return fmt.Errorf("unable to expand the template: %s, error: %s", x, err)
		}
		templates = append(templates, list...)
	}

	snippets := make(map[string]string)
	for _, x := range options.snippetsPath {
		list, err := expandFiles(utils.ExpandPath(x))
		if err != nil {
			return fmt.Errorf("unable to expand the snippets: %s, error: %s", x, err)
		}

		for _, j := range list {
			content, err := os.ReadFile(j)
			if err != nil {
				return fmt.Errorf("unable to read snippet: %s, error: %s", j, err)
			}
			snippets[path.Base(j)] = string(content)
		}
	}

	channel, err := kopsapi.LoadChannel(f.VFSContext(), options.channel)
	if err != nil {
		return fmt.Errorf("error loading channel %q: %v", options.channel, err)
	}

	// @step: render each of the templates, splitting on the documents
	r := templater.NewTemplater(channel)

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Verify each --snippets-path value exists and matches files from the command's working directory
  2. Use an absolute path or correct the relative path; confirm with `ls <path>`
  3. Check read permissions on the snippets directory
  4. If snippets are optional, remove the --snippets-path flag instead of pointing at an empty/missing location

Example fix

// before
kops toolbox template --template-path ./templates --snippets-path ./snippetz --values values.yaml

// after
kops toolbox template --template-path ./templates --snippets-path ./snippets --values values.yaml
Defensive patterns

Strategy: validation

Validate before calling

for _, p := range snippetPaths {
    expanded := utils.ExpandPath(p)
    matches, err := filepath.Glob(expanded)
    if err != nil || len(matches) == 0 {
        return fmt.Errorf("snippet path %q matches no files", p)
    }
}

Prevention

When it happens

Trigger: `kops toolbox template --snippets-path ./snippets` where the directory doesn't exist, the glob matches zero files, permissions deny access, or expandFiles hits an OS error reading the path.

Common situations: Wrong working directory so relative snippet paths don't exist; snippets folder renamed or not committed; typo in --snippets-path; glob syntax misunderstanding (e.g. expecting recursive matching without **).

Related errors


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