{"record":{"id":"d4ce8884833d2901","repo":"cilium/cilium","slug":"adding-key-type-w","errorCode":null,"errorMessage":"adding key type: %w","messagePattern":"adding key type: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tools/dpgen/util.go","lineNumber":211,"sourceCode":"\t}\n\n\tif a.ValueSize != b.ValueSize {\n\t\treturn fmt.Errorf(\"value size mismatch: %d != %d\", a.ValueSize, b.ValueSize)\n\t}\n\n\tif a.MaxEntries != b.MaxEntries {\n\t\treturn fmt.Errorf(\"max entries mismatch: %d != %d\", a.MaxEntries, b.MaxEntries)\n\t}\n\n\treturn nil\n}\n\n// addMapKV adds the BTF types of the map's key and value to the given BTF\n// builder.\nfunc addMapKV(bb *btf.Builder, added *set.Set[string], spec *ebpf.MapSpec) error {\n\tif spec.Key != nil {\n\t\tif err := addType(bb, added, spec.Key); err != nil {\n\t\t\treturn fmt.Errorf(\"adding key type: %w\", err)\n\t\t}\n\t}\n\tif spec.Value != nil {\n\t\tif err := addType(bb, added, spec.Value); err != nil {\n\t\t\treturn fmt.Errorf(\"adding value type: %w\", err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// addVariableType adds the BTF type of the variable to the given BTF builder.\nfunc addVariableType(bb *btf.Builder, added *set.Set[string], v *ebpf.VariableSpec) error {\n\tif v.Type == nil || v.Type.Type == nil {\n\t\treturn fmt.Errorf(\"no BTF type information\")\n\t}\n\n\treturn addType(bb, added, v.Type.Type)\n}","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/tools/dpgen/util.go#L193-L229","documentation":"addMapKV registers a map's BTF key and value types with a btf.Builder used by dpgen's -maps/-types commands. This error wraps a failure while adding the key type (spec.Key) to the builder — e.g. the BTF type could not be resolved or encoded. Callers runMaps and runTypes further wrap it with the map name.","triggerScenarios":"Running `dpgen -types` or `dpgen -maps` over ELF objects whose map has a Key BTF type that the builder cannot add (missing/corrupt BTF in the object, unsupported type constructs, deduplication conflicts).","commonSituations":"Objects compiled without BTF or with stripped BTF sections; clang versions producing BTF constructs the cilium/ebpf library can't parse; duplicate type names across objects clashing under the deduplicating builder.","solutions":["Recompile the BPF objects with BTF enabled (clang -g / -target bpf with BTF, not stripped) and rerun dpgen.","Inspect the wrapped inner error (strip this frame via errors.Unwrap) to see which BTF construct failed; adjust the C type or upgrade cilium/ebpf.","Check for clang/LLVM version incompatibilities and build with the toolchain version cilium requires.","Verify the object with `bpftool btf dump file <obj>` to confirm key BTF is present and valid."],"exampleFix":"// before: compiling without BTF\nclang -target bpf -c prog.c -o prog.o\n// after\nclang -target bpf -g -c prog.c -o prog.o","handlingStrategy":"validation","validationCode":"f, err := os.Open(objPath)\nif err != nil { return err }\nrd, err := elf.NewFile(f)\nif err != nil { return err }\nif rd.Section(\".BTF\") == nil {\n    return fmt.Errorf(\"%s has no .BTF section; rebuild with clang -g\", objPath)\n}","typeGuard":null,"tryCatchPattern":"if err := runTypes(cmd, args); err != nil {\n    if strings.Contains(err.Error(), \"adding key type:\") {\n        // verify object BTF with bpftool btf dump and rebuild with -g\n    }\n}","preventionTips":["Always compile BPF objects with -g so BTF is emitted","Use the clang/LLVM version mandated by cilium to avoid unparsable BTF","Sanity-check objects with `bpftool btf dump file <o>` before running dpgen"],"tags":["ebpf","btf","cilium","codegen"],"backgroundTag":"btf-type-resolution-failed","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}