Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions sdb/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,24 +634,31 @@ def pretty_print(self, objs: Iterable[drgn.Object]) -> None:
# pylint: disable=missing-docstring
raise NotImplementedError

def _call( # type: ignore[return]
self,
objs: Iterable[drgn.Object]) -> Optional[Iterable[drgn.Object]]:
def check_input_type(self,
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdb: range_tree: expected input of type range_tree_t *, but received type spa_t *
3 changes: 3 additions & 0 deletions tests/integration/test_core_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@

# ptype - bogus type
"ptype bogus_t",

# pretty printer passed incorrect type
"spa | range_tree"
]

CMD_TABLE = POS_CMDS + NEG_CMDS
Expand Down