Skip to content

Commit 50f6061

Browse files
committed
chore: Add logging
1 parent bfe7a84 commit 50f6061

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

src/pybag/mcap_reader.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,39 +78,25 @@ def end_time(self) -> int:
7878
# Message Access
7979

8080
def _expand_topics(self, topic: str | list[str]) -> list[str]:
81-
"""Expand topic specification to list of concrete topic names.
81+
"""Expand topic patterns to list of concrete topic names.
8282
8383
Handles:
8484
- Single topic string (may contain glob pattern like "/sensor/*")
8585
- List of topic strings (each may contain glob patterns)
8686
8787
Args:
88-
topic: Topic specification (string or list of strings)
88+
topic: Topic pattern (string or list of strings)
8989
9090
Returns:
9191
Deduplicated list of concrete topic names that exist in the file
9292
"""
93-
# Get all available topics
9493
available_topics = self.get_topics()
95-
96-
# Normalize input to list
9794
topic_patterns = [topic] if isinstance(topic, str) else topic
98-
99-
# Expand patterns to concrete topics
10095
matched_topics = set()
10196
for pattern in topic_patterns:
102-
# Check if pattern contains glob characters
103-
if '*' in pattern or '?' in pattern:
104-
# Use fnmatch to find matching topics
105-
matches = fnmatch.filter(available_topics, pattern)
106-
matched_topics.update(matches)
107-
else:
108-
# Exact match - check if topic exists
109-
if pattern in available_topics:
110-
matched_topics.add(pattern)
111-
112-
# Return sorted list for consistent ordering
113-
return sorted(matched_topics)
97+
matches = fnmatch.filter(available_topics, pattern)
98+
matched_topics.update(matches)
99+
return list(matched_topics)
114100

115101
def messages(
116102
self,
@@ -141,24 +127,29 @@ def messages(
141127
# If empty list we return no messages
142128
if (concrete_topics := self._expand_topics(topic)) == []:
143129
return
130+
logging.debug(f"Expanded topics: {concrete_topics}")
144131

145132
channel_infos = {} # dict[channel_id, tuple[channel_record, schema]]
146133
for topic_name in concrete_topics:
147134
channel_id = self._reader.get_channel_id(topic_name)
148135
if channel_id is None:
136+
logging.warning(f"{topic_name} corresponds to no channel")
149137
continue # Skip topics that don't exist
150138

151139
channel_record = self._reader.get_channel(channel_id)
152140
if channel_record is None:
141+
logging.warning(f"No channel record for {topic_name} ({channel_id})")
153142
continue
154143

155144
message_schema = self._reader.get_channel_schema(channel_id)
156145
if message_schema is None:
157-
raise McapUnknownSchemaError(f'Unknown schema for channel {channel_id}')
146+
logging.warning(f"Unknown schema for {topic_name} ({channel_id})")
147+
continue
158148

159149
channel_infos[channel_id] = (channel_record, message_schema)
160150

161151
if not channel_infos:
152+
logging.warning(f'Nothing to retrieve!')
162153
return
163154

164155
if (message_deserializer := self._message_deserializer) is None:

0 commit comments

Comments
 (0)