{"record":{"id":"4de6d35577c48ecb","repo":"grafana/k6","slug":"failed-to-get-absolute-path-for-template-s-w","errorCode":null,"errorMessage":"failed to get absolute path for template %s: %w","messagePattern":"failed to get absolute path for template (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/templates/templates.go","lineNumber":81,"sourceCode":"}\n\n// GetTemplate selects the appropriate template based on the type\nfunc (tm *TemplateManager) GetTemplate(tpl string) (*template.Template, error) {\n\t// First check built-in templates\n\tswitch tpl {\n\tcase MinimalTemplate:\n\t\treturn tm.minimalTemplate, nil\n\tcase ProtocolTemplate:\n\t\treturn tm.protocolTemplate, nil\n\tcase BrowserTemplate:\n\t\treturn tm.browserTemplate, nil\n\t}\n\n\t// Then check if it's a file path\n\tif isFilePath(tpl) {\n\t\ttplPath, err := filepath.Abs(tpl)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to get absolute path for template %s: %w\", tpl, err)\n\t\t}\n\n\t\t// Read the template content using the provided filesystem\n\t\tcontent, err := fsext.ReadFile(tm.fs, tplPath)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to read template file %s: %w\", tpl, err)\n\t\t}\n\n\t\ttmpl, err := template.New(filepath.Base(tplPath)).Parse(string(content))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to parse template file %s: %w\", tpl, err)\n\t\t}\n\n\t\treturn tmpl, nil\n\t}\n\n\t// Check if there's a file with this name in current directory\n\texists, err := fsext.Exists(tm.fs, fsext.JoinFilePath(\".\", tpl))","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/cmd/templates/templates.go#L63-L99","documentation":"For `k6 new -t <path>`, values containing a path separator are resolved to an absolute path with filepath.Abs before being read. Abs essentially never fails unless the OS cannot determine the current working directory (deleted cwd, permission trouble), so this error is environmental; the wrapped %w carries the underlying OS error.","triggerScenarios":"Running k6 from a directory that was deleted out from under the process (classic getcwd ENOENT); unusual container/sandbox setups where the cwd is inaccessible.","commonSituations":"Shell scripts that cd into temp dirs which a parallel cleanup removes; container overlays where the workdir is pruned mid-session.","solutions":["Run k6 from an existing directory you can read: cd to a stable path and retry","Pass an absolute template path so resolution depends less on cwd","Fix the environment: recreate the deleted directory or restart the shell/container — the wrapped error names the OS cause"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# ensure the working directory still resolves before running k6\nif ! pwd -P >/dev/null 2>&1; then\n  echo \"current directory is gone — switching to a stable one\" >&2\n  cd /tmp || exit 1\nfi\nk6 new -t \"$HOME/templates/my.js\" new-script.js","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run k6 from stable, long-lived directories; avoid temp dirs that cleanup jobs may delete","Pass absolute -t paths to reduce dependence on cwd resolution","If this fires, treat it as an environment smell — the wrapped OS error says exactly what failed"],"tags":["k6","k6-new","template","filesystem","path"],"backgroundTag":"path-resolution-failed","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"}