diff --git a/pythonbpf/maps/maps_pass.py b/pythonbpf/maps/maps_pass.py index 083b24a..7e3b1ed 100644 --- a/pythonbpf/maps/maps_pass.py +++ b/pythonbpf/maps/maps_pass.py @@ -175,10 +175,16 @@ def process_bpf_map(func_node, compilation_context): if isinstance(rval, ast.Call) and isinstance(rval.func, ast.Name): handler = MapProcessorRegistry.get_processor(rval.func.id) - if handler: - return handler(map_name, rval, compilation_context) - else: - logger.warning(f"Unknown map type {rval.func.id}, defaulting to HashMap") - return process_hash_map(map_name, rval, compilation_context) + if handler is None: + # Falling back to a hash map here used to produce an object that + # compiled cleanly and was then rejected by the kernel, because the + # map carried the wrong type and none of the real map type's + # validation ran. A misspelled map type is a program error. + known = ", ".join(sorted(MapProcessorRegistry.known_types())) + raise ValueError( + f"Unknown map type '{rval.func.id}' returned by '{map_name}'. " + f"Known map types: {known}" + ) + return handler(map_name, rval, compilation_context) else: raise ValueError("Function under @map must return a map") diff --git a/pythonbpf/maps/maps_utils.py b/pythonbpf/maps/maps_utils.py index 194b408..decf04b 100644 --- a/pythonbpf/maps/maps_utils.py +++ b/pythonbpf/maps/maps_utils.py @@ -33,3 +33,8 @@ class MapProcessorRegistry: def get_processor(cls, map_type_name): """Get the processor function for a map type""" return cls._processors.get(map_type_name) + + @classmethod + def known_types(cls): + """Names of every registered map type, for error messages""" + return list(cls._processors)