{"record":{"id":"4f59a72c320574bf","repo":"go-delve/delve","slug":"key-type-not-supported-t","errorCode":null,"errorMessage":"key type not supported %T","messagePattern":"key type not supported %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/terminal/starbind/conv.go","lineNumber":543,"sourceCode":"func (v mapVariableAsStarlarkValue) Type() string {\n\treturn v.v.Type\n}\n\nfunc (v mapVariableAsStarlarkValue) Get(key starlark.Value) (starlark.Value, bool, error) {\n\tvar keyExpr string\n\tswitch key := key.(type) {\n\tcase starlark.Int:\n\t\tkeyExpr = key.String()\n\tcase starlark.Float:\n\t\tkeyExpr = fmt.Sprintf(\"%g\", float64(key))\n\tcase starlark.String:\n\t\tkeyExpr = fmt.Sprintf(\"%q\", string(key))\n\tcase starlark.Bool:\n\t\tkeyExpr = fmt.Sprintf(\"%v\", bool(key))\n\tcase structVariableAsStarlarkValue:\n\t\tkeyExpr = varAddrExpr(key.v)\n\tdefault:\n\t\treturn starlark.None, false, fmt.Errorf(\"key type not supported %T\", key)\n\t}\n\n\tv2 := v.env.autoLoad(fmt.Sprintf(\"%s[%s]\", varAddrExpr(v.v), keyExpr))\n\tr, err := v.env.variableValueToStarlarkValue(v2, false)\n\tif err != nil {\n\t\tif err.Error() == \"key not found\" {\n\t\t\treturn starlark.None, false, nil\n\t\t}\n\t\treturn starlark.None, false, err\n\t}\n\treturn r, true, nil\n}\n\nfunc (v mapVariableAsStarlarkValue) Items() []starlark.Tuple {\n\tr := make([]starlark.Tuple, 0, len(v.v.Children)/2)\n\tfor i := 0; i < len(v.v.Children); i += 2 {\n\t\tr = append(r, mapStarlarkTupleAt(v.v, v.env, i))\n\t}","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/terminal/starbind/conv.go#L525-L561","documentation":"The Starlark mapping wrapper over a Delve variable (mapIndex/Get) only supports string, bool and structVariable (variable) keys; any other Starlark key type (int, tuple, None, etc.) is rejected when evaluating the map index in the debuggee.","triggerScenarios":"`some_map_var[42]` or `some_map_var[(1,2)]` in a Starlark script where the Delve variable is a Go map whose keys must be expressed as an evaluated expression string.","commonSituations":"Indexing Go maps with numeric literals in scripts; Delve evaluates the index in the target process, so keys must be round-trippable expressions.","solutions":["Use a string key: m[\"key\"] — for integer keys quote them so they are sent as an expression, e.g. m[str(42)] if supported, or use m['%d' % 42] form","Index the map directly via the debugger expression instead: env autoLoad of var[expr]","Restructure the script to iterate keys via the debugger rather than indexing by native Starlark ints"],"exampleFix":"# before\nm[42]            # int key not supported\n# after\nm[str(42)]       # or 'm[42]' evaluated as debugger expression","handlingStrategy":"type-guard","validationCode":"if not isinstance(key, (str, bool)):\n    raise TypeError(\"map index key must be str or bool, got %s\" % type(key))","typeGuard":"def is_supported_key(k):\n    return isinstance(k, (str, bool)) or hasattr(k, 'v')  # structVariableAsStarlarkValue","tryCatchPattern":"try:\n    v = m[key]\nexcept Exception as e:\n    if \"key type not supported\" in str(e):\n        v = m[str(key)]  # re-index as string expression\n    else:\n        raise","preventionTips":["Always use string (or bool) keys when indexing debugger map variables","Convert numeric keys with str()/format before indexing","Prefer debugger-expression indexing for non-string key types"],"tags":["starlark","delve","scripting","map-index"],"backgroundTag":"unsupported-key-type","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}