{"record":{"id":"87a56be359449816","repo":"go-delve/delve","slug":"key-not-found","errorCode":null,"errorMessage":"key not found","messagePattern":"key not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/proc/eval.go","lineNumber":2924,"sourceCode":"\t\tif first {\n\t\t\tfirst = false\n\t\t\tif err := idx.isType(key.RealType, key.Kind); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t}\n\t\teql, err := compareOp(token.EQL, key, idx)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif eql {\n\t\t\treturn it.value(), nil\n\t\t}\n\t}\n\tif v.Unreadable != nil {\n\t\treturn nil, v.Unreadable\n\t}\n\t// go would return zero for the map value type here, we do not have the ability to create zeroes\n\treturn nil, errors.New(\"key not found\")\n}\n\n// LoadResliced returns a new array, slice or map that starts at index start and contains\n// up to cfg.MaxArrayValues children.\nfunc (v *Variable) LoadResliced(start int, cfg LoadConfig) (newV *Variable, err error) {\n\tswitch v.Kind {\n\tcase reflect.Array, reflect.Slice:\n\t\tlow, high := int64(start), int64(start+cfg.MaxArrayValues)\n\t\tif high > v.Len {\n\t\t\thigh = v.Len\n\t\t}\n\t\tnewV, err = v.reslice(low, high, false)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\tcase reflect.Map:\n\t\tnewV = v.clone()\n\t\tnewV.Children = nil","sourceCodeStart":2906,"sourceCodeEnd":2942,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2906-L2942","documentation":"When evaluating a map index expression m[k], Delve looks up k among the loaded map entries. Go would return the zero value for a missing key, but Delve cannot fabricate zero values of arbitrary types from debug info, so instead of returning a zero it throws 'key not found' when the key is absent from the map (or from the loaded entries).","triggerScenarios":"Evaluating 'print m[\"missing\"]' or 'print m[someKey]' where the key does not exist in the map, or exists but was not among the loaded entries (map larger than MaxArrayValues, or mapSkip/LoadResliced windowing).","commonSituations":"Probing whether a map contains a key during debugging; inspecting a large map where the desired key falls outside the first N loaded entries; typo'd or type-mismatched key literals (e.g. int vs string).","solutions":["Verify the key exists: iterate/inspect the map with 'print m' (careful with large maps) or check 'print len(m)'","Check membership via the program's logic instead: set a breakpoint where the code does v, ok := m[k] and inspect ok","If the map is large, raise 'config max-array-values' so the key's entry gets loaded, then retry the lookup","Confirm the key literal type matches the map key type (e.g. use 'print m[42]' not 'print m[\"42\"]' for int keys)"],"exampleFix":"// before (dlv CLI)\n(dlv) print userMap[\"alice\"]   // key absent -> error\n\n// after\n(dlv) print userMap            // inspect actual keys\n(dlv) print userMap[\"bob\"]     // use an existing key","handlingStrategy":"fallback","validationCode":"// before a map lookup in dlv, confirm the key exists by inspecting entries\n(dlv) print m               // small maps only\n(dlv) print len(m)\n// or check membership at a breakpoint where the code does v, ok := m[k]","typeGuard":"func mapHasKey(keys []string, k string) bool {\n    for _, key := range keys { if key == k { return true } }\n    return false\n}","tryCatchPattern":"// RPC client pattern\nval, err := client.EvalVariable(scope, \"m[\\\"key\\\"]\", cfg)\nif err != nil && strings.Contains(err.Error(), \"key not found\") {\n    // treat as missing key: use the zero value of the map's value type\n    fmt.Println(\"key absent in debuggee map\")\n}","preventionTips":["Remember Delve returns an error, not a zero value, for missing map keys","Verify the key literal's type matches the map's key type","Raise max-array-values so large maps load the entry containing your key","Use program-level 'v, ok := m[k]' checks at breakpoints for reliable membership tests"],"tags":["go","debugger","map-lookup","key-not-found"],"backgroundTag":"map-key-not-found","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}