diff --git a/sdb/command.py b/sdb/command.py index 49e1d9b3..a7018e3a 100644 --- a/sdb/command.py +++ b/sdb/command.py @@ -634,24 +634,32 @@ def pretty_print(self, objs: Iterable[drgn.Object]) -> None: # pylint: disable=missing-docstring raise NotImplementedError - def _call( # type: ignore[return] + def check_input_type( self, - objs: Iterable[drgn.Object]) -> Optional[Iterable[drgn.Object]]: + objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]: """ - This function will call pretty_print() on each input object, - verifying the types as we go. + This function acts as a generator, checking that each passed object + matches the input type for the command """ - assert self.input_type is not None type_name = type_canonicalize_name(self.input_type) for obj in objs: if type_canonical_name(obj.type_) != type_name: raise CommandError( self.name, - f'exepected input of type {self.input_type}, but received ' + f'expected input of type {self.input_type}, but received ' f'type {obj.type_}') + yield obj - self.pretty_print([obj]) + def _call( # type: ignore[return] + self, + objs: Iterable[drgn.Object]) -> Optional[Iterable[drgn.Object]]: + """ + This function will call pretty_print() on each input object, + verifying the types as we go. + """ + assert self.input_type is not None + self.pretty_print(self.check_input_type(objs)) class Locator(Command): diff --git a/tests/integration/data/regression_output/core/spa | range_tree b/tests/integration/data/regression_output/core/spa | range_tree new file mode 100644 index 00000000..91a26850 --- /dev/null +++ b/tests/integration/data/regression_output/core/spa | range_tree @@ -0,0 +1 @@ +sdb: range_tree: expected input of type range_tree_t *, but received type spa_t * diff --git a/tests/integration/test_core_generic.py b/tests/integration/test_core_generic.py index c979e85e..45018c73 100644 --- a/tests/integration/test_core_generic.py +++ b/tests/integration/test_core_generic.py @@ -168,6 +168,9 @@ # ptype - bogus type "ptype bogus_t", + + # pretty printer passed incorrect type + "spa | range_tree" ] CMD_TABLE = POS_CMDS + NEG_CMDS