Skip to content
Merged
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
7 changes: 7 additions & 0 deletions elementary/tracking/anonymous_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ def _get_exception_properties(exc: Exception):
props.update(exc.anonymous_tracking_context)
return props

def register_group(
self, group_type: str, group_identifier: str, group_props: Optional[dict] = None
) -> None:
if self._do_not_track:
return
return super().register_group(group_type, group_identifier, group_props)

Comment on lines +91 to +97
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Make register_group exception-safe; analytics must never break CLI

Mirror the defensive pattern used in _send_anonymous_event by swallowing PostHog errors. Also no need to return the super() call since return type is None.

 def register_group(
     self, group_type: str, group_identifier: str, group_props: Optional[dict] = None
 ) -> None:
     if self._do_not_track:
         return
-    return super().register_group(group_type, group_identifier, group_props)
+    try:
+        super().register_group(group_type, group_identifier, group_props)
+    except Exception:
+        logger.debug("Unable to register tracking group.", exc_info=True)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def register_group(
self, group_type: str, group_identifier: str, group_props: Optional[dict] = None
) -> None:
if self._do_not_track:
return
return super().register_group(group_type, group_identifier, group_props)
def register_group(
self, group_type: str, group_identifier: str, group_props: Optional[dict] = None
) -> None:
if self._do_not_track:
return
try:
super().register_group(group_type, group_identifier, group_props)
except Exception:
logger.debug("Unable to register tracking group.", exc_info=True)
🤖 Prompt for AI Agents
In elementary/tracking/anonymous_tracking.py around lines 91 to 97, change
register_group so it does not return the super call and is exception-safe: if
self._do_not_track return early, otherwise call super().register_group(...)
inside a try/except block that catches PostHog/network/other exceptions and
swallows them (optionally logging at debug level) so analytics errors cannot
raise out of the CLI.


class AnonymousCommandLineTracking(AnonymousTracking):
def track_cli_start(
Expand Down