{"record":{"id":"43840ccda0a9aa29","repo":"istio/istio","slug":"path-not-found-at-element-s-in-path-s","errorCode":null,"errorMessage":"path not found at element %s in path %s","messagePattern":"path not found at element (.+?) in path (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"operator/pkg/tpath/tree.go","lineNumber":235,"sourceCode":"\t\t\t\tnc.KeyToChild = idx\n\t\t\t\treturn getPathContext(nn, fullPath, remainPath[1:], createMissing)\n\t\t\t}\n\t\t}\n\t\treturn nil, false, fmt.Errorf(\"path %s: element %s not found\", fullPath, pe)\n\t}\n\n\tif util.IsMap(ncNode) {\n\t\tscope.Debug(\"map type\")\n\t\tvar nn any\n\t\tif m, ok := ncNode.(map[any]any); ok {\n\t\t\tnn, ok = m[pe]\n\t\t\tif !ok {\n\t\t\t\t// remainPath == 1 means the patch is creation of a new leaf.\n\t\t\t\tif createMissing || len(remainPath) == 1 {\n\t\t\t\t\tm[pe] = make(map[any]any)\n\t\t\t\t\tnn = m[pe]\n\t\t\t\t} else {\n\t\t\t\t\treturn nil, false, fmt.Errorf(\"path not found at element %s in path %s\", pe, fullPath)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif reflect.ValueOf(ncNode).IsNil() {\n\t\t\tncNode = make(map[string]any)\n\t\t\tnc.Node = ncNode\n\t\t}\n\t\tif m, ok := ncNode.(map[string]any); ok {\n\t\t\tnn, ok = m[pe]\n\t\t\tif !ok {\n\t\t\t\t// remainPath == 1 means the patch is creation of a new leaf.\n\t\t\t\tif createMissing || len(remainPath) == 1 {\n\t\t\t\t\tnextElementNPath := len(remainPath) > 1 && util.IsNPathElement(remainPath[1])\n\t\t\t\t\tif nextElementNPath {\n\t\t\t\t\t\tscope.Debug(\"map type, slice child\")\n\t\t\t\t\t\tm[pe] = make([]any, 0)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tscope.Debug(\"map type, map child\")","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/istio/istio/blob/8dc789c5cf17517c64e3c36cb3288230f149dfae/operator/pkg/tpath/tree.go#L217-L253","documentation":"During map traversal in strict mode (createMissing=false), a missing intermediate key with more than one path segment remaining cannot be auto-created, so getPathContext fails naming the missing element and the full path. (The same check repeats just below for map[string]any trees.) Leaf creation (remainPath length 1) is allowed even in this mode.","triggerScenarios":"Reading a.b.c with createMissing=false when b does not exist in the map[any]any tree — e.g. tpath.GetPathContext on spec.values.x.y before spec.values.x is set.","commonSituations":"Code querying optional config subtrees (components not present in the profile, values unset by the base); path typos in the middle segment; trees where an earlier step nulled the intermediate map.","solutions":["Treat as 'not found': check existence level by level before the strict read","Ensure the base values/profile defines the intermediate maps, or create them via a write API (SetPath) first","Fix the path typo at the reported element"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func walkExists(root any, segs []string) bool {\n    cur := root\n    for i, s := range segs {\n        switch m := cur.(type) {\n        case map[string]any:\n            v, ok := m[s]\n            if !ok || v == nil { return false }\n            cur = v\n        case map[any]any:\n            v, ok := m[s]\n            if !ok || v == nil { return false }\n            cur = v\n        default:\n            return false\n        }\n        _ = i\n    }\n    return true\n}","typeGuard":"func asMap(v any) (map[string]any, bool) {\n    m, ok := v.(map[string]any)\n    return m, ok\n}","tryCatchPattern":null,"preventionTips":["Verify each intermediate segment exists before strict reads (GetPathContext)","Use write APIs (SetPath with createMissing) to materialize intermediate maps before reading into them","Report the missing element name from the error to pinpoint the bad segment quickly"],"tags":["istio","tpath","tree","path","not-found","map"],"backgroundTag":null,"analyzedSha":"8dc789c5cf17517c64e3c36cb3288230f149dfae","analyzedAt":"2026-08-15T15:16:55.434Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}