{"record":{"id":"2de7362ddbb230a2","repo":"grafana/k6","slug":"error-initializing-template-manager-w","errorCode":null,"errorMessage":"error initializing template manager: %w","messagePattern":"error initializing template manager: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/new.go","lineNumber":50,"sourceCode":"\nfunc (c *newScriptCmd) run(_ *cobra.Command, args []string) (err error) {\n\ttarget := defaultNewScriptName\n\tif len(args) > 0 {\n\t\ttarget = args[0]\n\t}\n\n\tfileExists, err := fsext.Exists(c.gs.FS, target)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif fileExists && !c.overwriteFiles {\n\t\treturn fmt.Errorf(\"%s already exists. Use the `--force` flag to overwrite it\", target)\n\t}\n\n\t// Initialize template manager and validate template before creating any files\n\ttm, err := templates.NewTemplateManager(c.gs.FS)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error initializing template manager: %w\", err)\n\t}\n\n\ttmpl, err := tm.GetTemplate(c.templateType)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error retrieving template: %w\", err)\n\t}\n\n\t// Prepare template arguments\n\targsStruct := templates.TemplateArgs{\n\t\tScriptName: target,\n\t\tProjectID:  c.projectID,\n\t}\n\n\t// First render the template to a buffer to validate it\n\tvar buf strings.Builder\n\tif err := templates.ExecuteTemplate(&buf, tmpl, argsStruct); err != nil {\n\t\treturn fmt.Errorf(\"failed to execute template %s: %w\", c.templateType, err)\n\t}","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/new.go#L32-L68","documentation":"Returned by `k6 new` when templates.NewTemplateManager(c.gs.FS) fails to initialize. The manager parses the embedded template registry at construction; failure means the embedded templates could not be prepared — effectively a broken/custom k6 build rather than anything the user supplied (note it runs before any template is selected or any file is created).","triggerScenarios":"Running `k6 new` with a corrupted or non-stock k6 binary whose embedded template assets fail to parse; custom xk6 builds that modified the templates package; filesystem-level failures of the injected afero FS in tests/embedded scenarios.","commonSituations":"Essentially unseen with official binaries; surfaces in development forks after editing internal/templates, or when a partially downloaded binary is executed.","solutions":["Re-download/reinstall the official k6 binary for your platform and verify with `k6 version`","If this is a custom xk6 build, rebuild from a clean checkout (make build) — the error is inside template-manager initialization, not your invocation","File an issue upstream with `k6 version` output if a stock binary reproduces it"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Smoke the binary's scaffolding path once during provisioning\nk6 version >/dev/null && k6 new --force /tmp/_smoke.js >/dev/null || { echo 'k6 new broken on this build'; exit 1; }\nrm -f /tmp/_smoke.js","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install k6 from official release artifacts with checksum verification","Run `make check` on custom xk6 builds before distribution"],"tags":["cli","templates","internal","scaffolding"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}