{"record":{"id":"54cef1c2226dda22","repo":"grafana/k6","slug":"failed-to-execute-template-s-w","errorCode":null,"errorMessage":"failed to execute template %s: %w","messagePattern":"failed to execute template (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/new.go","lineNumber":67,"sourceCode":"\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}\n\n\t// Only create the file after template rendering succeeds\n\tfd, err := c.gs.FS.Create(target)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tdefer func() {\n\t\tif cerr := fd.Close(); cerr != nil {\n\t\t\tif _, werr := fmt.Fprintf(c.gs.Stderr, \"error closing file: %v\\n\", cerr); werr != nil {\n\t\t\t\terr = fmt.Errorf(\"error writing error message to stderr: %w\", werr)\n\t\t\t} else {\n\t\t\t\terr = cerr\n\t\t\t}\n\t\t}\n\t}()\n","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/cmd/new.go#L49-L85","documentation":"Wrapped error in 'k6 new': rendering the selected template to a buffer failed (templates.ExecuteTemplate). Usually a malformed template file (custom path) or missing expected fields — k6 renders before writing to avoid leaving broken files.","triggerScenarios":"Thrown at internal/cmd/new.go:67 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Validate the custom template's Go template syntax","Use a built-in template name if the custom one fails","Check the wrapped error for the exact template parse/execute failure"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}