grafana/k6 · error
error retrieving template
Error message
error retrieving template: %w
What it means
Wrapped error in 'k6 new': the requested --template value does not match a built-in template (minimal, protocol, browser) and cannot be resolved as a custom template file path, so tm.GetTemplate failed.
Solutions
- Use one of the built-in template names: minimal, protocol, or browser
- If using a custom template, verify the relative/absolute path exists and is readable
- Check the wrapped error for path resolution details
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/cmd/new.go:55 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/0af339886aebcbad.
Report an issue: GitHub.
Appendix: source
Thrown at internal/cmd/new.go:55
}
fileExists, err := fsext.Exists(c.gs.FS, target)
if err != nil {
return err
}
if fileExists && !c.overwriteFiles {
return fmt.Errorf("%s already exists. Use the `--force` flag to overwrite it", target)
}
// Initialize template manager and validate template before creating any files
tm, err := templates.NewTemplateManager(c.gs.FS)
if err != nil {
return fmt.Errorf("error initializing template manager: %w", err)
}
tmpl, err := tm.GetTemplate(c.templateType)
if err != nil {
return fmt.Errorf("error retrieving template: %w", err)
}
// Prepare template arguments
argsStruct := templates.TemplateArgs{
ScriptName: target,
ProjectID: c.projectID,
}
// First render the template to a buffer to validate it
var buf strings.Builder
if err := templates.ExecuteTemplate(&buf, tmpl, argsStruct); err != nil {
return fmt.Errorf("failed to execute template %s: %w", c.templateType, err)
}
// Only create the file after template rendering succeeds
fd, err := c.gs.FS.Create(target)
if err != nil {
return errView on GitHub (pinned to 01ffac6f24)