{"record":{"id":"73b5ae89aeda9758","repo":"hashicorp/nomad","slug":"error-opening-env-template-v","errorCode":null,"errorMessage":"error opening env template: %v","messagePattern":"error opening env template: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocrunner/taskrunner/template/template.go","lineNumber":1086,"sourceCode":"\tuser        string\n\tgroup       string\n\ttaskID      string\n\tcontents    []byte\n}\n\n// loadTemplateEnv loads task environment variables from all templates.\nfunc loadTemplateEnv(tmpls []*structs.Template, taskEnv *taskenv.TaskEnv) (map[string]string, error) {\n\tall := make(map[string]string, 50)\n\tfor _, t := range tmpls {\n\t\tif !t.Envvars {\n\t\t\tcontinue\n\t\t}\n\n\t\t// we checked escape before we rendered the file\n\t\tdest, _ := taskEnv.ClientPath(t.DestPath, true)\n\t\tf, err := os.Open(dest)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error opening env template: %v\", err)\n\t\t}\n\t\tdefer f.Close()\n\n\t\t// Parse environment fil\n\t\tvars, err := envparse.Parse(f)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error parsing env template %q: %v\", dest, err)\n\t\t}\n\t\tmaps.Copy(all, vars)\n\t}\n\treturn all, nil\n}\n","sourceCodeStart":1068,"sourceCodeEnd":1099,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocrunner/taskrunner/template/template.go#L1068-L1099","documentation":"In loadTemplateEnv, a template marked envvars=true has a rendered destination file that cannot be opened via os.Open — typically the template rendered to a path that does not exist, was interpolated to a bad dest, or permissions deny reading. The whole env-loading pass fails, failing the task run hook.","triggerScenarios":"Thrown at client/allocrunner/taskrunner/template/template.go:1086 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the template's destination path renders and exists before env parsing","Check taskDir permissions and that ClientPath interpolation resolves inside the allocation dir","Ensure the template actually rendered (DidRender) before loadTemplateEnv is invoked"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}