{"record":{"id":"bf8f15f58bbafaa5","repo":"go-delve/delve","slug":"type-assertion-failed","errorCode":null,"errorMessage":"type assertion failed","messagePattern":"type assertion failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/dwarf/reader/reader.go","lineNumber":44,"sourceCode":"}\n\n// SeekToEntry moves the reader to an arbitrary entry.\nfunc (reader *Reader) SeekToEntry(entry *dwarf.Entry) error {\n\treader.Seek(entry.Offset)\n\t// Consume the current entry so .Next works as intended\n\t_, err := reader.Next()\n\treturn err\n}\n\n// AddrFor returns the address for the named entry.\nfunc (reader *Reader) AddrFor(name string, staticBase uint64, ptrSize int) (uint64, error) {\n\tentry, err := reader.FindEntryNamed(name, false)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tinstructions, ok := entry.Val(dwarf.AttrLocation).([]byte)\n\tif !ok {\n\t\treturn 0, errors.New(\"type assertion failed\")\n\t}\n\taddr, _, err := op.ExecuteStackProgram(op.DwarfRegisters{StaticBase: staticBase}, instructions, ptrSize, nil)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\treturn uint64(addr), nil\n}\n\nvar ErrTypeNotFound = errors.New(\"no type entry found, use 'types' for a list of valid types\")\n\n// SeekToType moves the reader to the type specified by the entry,\n// optionally resolving typedefs and pointer types. If the reader is set\n// to a struct type the NextMemberVariable call can be used to walk all member data.\nfunc (reader *Reader) SeekToType(entry *dwarf.Entry, resolveTypedefs bool, resolvePointerTypes bool) (*dwarf.Entry, error) {\n\toffset, ok := entry.Val(dwarf.AttrType).(dwarf.Offset)\n\tif !ok {\n\t\treturn nil, errors.New(\"entry does not have a type attribute\")\n\t}","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/dwarf/reader/reader.go#L26-L62","documentation":"In Reader.AddrFor, the DWARF entry found by name is expected to have a DW_AT_location attribute holding a []byte expression. If the attribute exists but its value is not a byte slice (e.g., it is a block/list form the parser returned as another type, or a location list), the type assertion fails and this generic error is returned.","triggerScenarios":"reader.AddrFor(name) on an entry whose AttrLocation value is not []byte — for instance a location list (loclistptr) rather than a single expression.","commonSituations":"Variables with dynamic location lists (optimized code), querying a non-variable entry that happens to have a location attribute, or DWARF version differences changing attribute form.","solutions":["Use InstructionsForEntry/InstructionsForEntryNamed only for entries with static expressions","For optimized builds, evaluate locations through proc's variable evaluation which handles location lists","Check the entry's attribute form with the DWARF dumper before calling AddrFor"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func hasStaticLocation(e *dwarf.Entry) bool {\n    _, ok := e.Val(dwarf.AttrLocation).([]byte)\n    return ok\n}","tryCatchPattern":null,"preventionTips":["Guard with a type assertion on the attribute before calling AddrFor","Route loclist-based locations to a full variable evaluator"],"tags":["dwarf","type-assertion","location-attribute"],"backgroundTag":"dwarf-attribute-type-mismatch","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}