{"record":{"id":"044595d125ede33e","repo":"hashicorp/nomad","slug":"invalid-type-for-node-variable-t","errorCode":null,"errorMessage":"invalid type for node variable: %T","messagePattern":"invalid type for node variable: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/taskenv/env.go","lineNumber":327,"sourceCode":"\tfor k, v := range t.TaskSecrets {\n\t\tif err := addNestedKey(allMap, k, v); err != nil {\n\t\t\terrs[k] = err\n\t\t}\n\t}\n\n\t// Add flat envMap as a Map to allMap so users can access any key via\n\t// HCL2's indexing syntax: ${env[\"foo...bar\"]}\n\tallMap[\"env\"] = cty.MapVal(envMap)\n\n\t// Add meta and attr to node if they exist to properly namespace things\n\t// a bit.\n\tnodeMapI, ok := allMap[\"node\"]\n\tif !ok {\n\t\treturn nil, nil, fmt.Errorf(\"missing node variable\")\n\t}\n\tnodeMap, ok := nodeMapI.(map[string]any)\n\tif !ok {\n\t\treturn nil, nil, fmt.Errorf(\"invalid type for node variable: %T\", nodeMapI)\n\t}\n\tif attrMap, ok := allMap[\"attr\"]; ok {\n\t\tnodeMap[\"attr\"] = attrMap\n\t}\n\tif metaMap, ok := allMap[\"meta\"]; ok {\n\t\tnodeMap[\"meta\"] = metaMap\n\t}\n\n\t// ctyify the entire tree of strings and maps\n\ttree, err := ctyify(allMap)\n\tif err != nil {\n\t\t// This should not be possible and is likely a programming\n\t\t// error. Invalid user input should be cleaned earlier.\n\t\treturn nil, nil, err\n\t}\n\n\treturn tree, errs, nil\n}","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/taskenv/env.go#L309-L345","documentation":"After locating allMap[\"node\"], AllValues asserts it is a map[string]any so attr/meta subtrees can be attached. If something stored a non-map value under the 'node' key (only possible via a 'node' env-var-style key colliding with a cty.Value or string), the type assertion fails and this fatal error is returned with the offending Go type.","triggerScenarios":"An entry keyed under the 'node' path in EnvMap/NodeAttrs resolved to a non-map (e.g. a scalar overwrote the 'node' object, or a cty.Value was added via addNestedKey so allMap[\"node\"] is not map[string]any).","commonSituations":"Custom code or tests inserting a key like \"node\" (no dot) directly into EnvMap/NodeAttrs; mixing raw cty.Value objects into the nested map before AllValues; client plugins feeding unexpected types into the env builder.","solutions":["Ensure no top-level key exactly named \"node\" (without a dot segment) is added to EnvMap or NodeAttrs; use node.<field> keys","Store only strings under NodeAttrs/EnvMap keys; reserve cty.Value for the final tree, not the intermediate maps","Inspect the %T in the message to find which code path inserted the wrong type","If inside Nomad core with no custom plugins, report upstream — this should be unreachable"],"exampleFix":"// before: scalar clobbers the node object\nenvMap[\"node\"] = \"wrong\"\n// after: nest under a dotted node key\nenvMap[\"node.custom\"] = \"value\"","handlingStrategy":"type-guard","validationCode":"// Go: before calling AllValues, ensure the 'node' slot is a map\nif v, ok := allMap[\"node\"]; ok {\n    if _, isMap := v.(map[string]any); !isMap {\n        return fmt.Errorf(\"node variable has non-map type %T; remove direct 'node' keys\", v)\n    }\n}","typeGuard":"// Go\nfunc nodeMap(all map[string]any) (map[string]any, bool) {\n    v, ok := all[\"node\"]\n    if !ok {\n        return nil, false\n    }\n    m, ok := v.(map[string]any)\n    return m, ok\n}","tryCatchPattern":"// Go\n_, _, err := tenv.AllValues()\nif err != nil && strings.HasPrefix(err.Error(), \"invalid type for node variable\") {\n    return fmt.Errorf(\"a non-dotted 'node' key overwrote the node object: %w\", err)\n}","preventionTips":["Never add a bare \"node\" key (without a dot) to EnvMap or NodeAttrs","Keep TaskEnv intermediate maps string-valued only; ctyify handles cty conversion","Inspect the %T in the error to identify the offending insertion site","Prefer dotted keys like node.custom for custom attributes"],"tags":["nomad","taskenv","interpolation","type-error"],"backgroundTag":"invalid-node-variable-type","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"}