Merge branch 'improve-required-event-not-found-message' into 'master'

Improve RequiredEventNotFoundError message

See merge request micro-ROS/ros_tracing/tracetools_analysis!66
This commit is contained in:
Christophe Bedard 2020-05-23 15:22:36 +00:00
commit 0b55273881

View file

@ -282,7 +282,7 @@ class Processor():
"""Processor class, which dispatches events to event handlers."""
class RequiredEventNotFoundError(RuntimeError):
"""When a trace does not contain one event required by an EventHandler."""
"""When a trace does not contain at least one event required by an EventHandler."""
pass
@ -380,11 +380,14 @@ class Processor():
) -> None:
event_names = self.get_event_names(events)
# Check names separately so that we can know which event from which handler is missing
missing_events: Dict[str, Set[str]] = defaultdict(set)
for handler in self._expanded_handlers:
for name in handler.required_events():
if name not in event_names:
missing_events[handler.__class__.__name__].add(name)
if missing_events:
raise self.RequiredEventNotFoundError(
f'missing event {name} for {handler.__class__.__name__}'
f'missing events: {dict(missing_events)}'
)
def process(