|
27 | 27 |
|
28 | 28 | import asyncio |
29 | 29 | import contextlib |
| 30 | +import logging |
30 | 31 | import os |
31 | 32 | import sys |
32 | 33 | import time |
|
83 | 84 | from ..state import ConnectionState |
84 | 85 | from ..types.components import Component as ComponentPayload |
85 | 86 |
|
| 87 | +_log = logging.getLogger(__name__) |
| 88 | + |
86 | 89 | V = TypeVar("V", bound="BaseView", covariant=True) |
87 | 90 |
|
88 | 91 |
|
@@ -756,7 +759,7 @@ def clear_items(self) -> Self: |
756 | 759 | self.__weights.clear() |
757 | 760 | return self |
758 | 761 |
|
759 | | - def refresh(self, components: list[Component]): |
| 762 | + def _refresh(self, components: list[Component]): |
760 | 763 | # This is pretty hacky at the moment |
761 | 764 | old_state: dict[tuple[int, str], ViewItem[V]] = { |
762 | 765 | (item.type.value, item.custom_id): item |
@@ -935,7 +938,7 @@ def add_item(self, item: ViewItem[V]) -> Self: |
935 | 938 | super().add_item(item) |
936 | 939 | return self |
937 | 940 |
|
938 | | - def refresh(self, components: list[Component]): |
| 941 | + def _refresh(self, components: list[Component]): |
939 | 942 | # Refreshes view data using discord's values |
940 | 943 | # Assumes the components and items are identical |
941 | 944 | if not components: |
@@ -1039,4 +1042,9 @@ def update_from_message(self, message_id: int, components: list[ComponentPayload |
1039 | 1042 | # pre-req: is_message_tracked == true |
1040 | 1043 | view = self._synced_message_views[message_id] |
1041 | 1044 | components = [_component_factory(d, state=self._state) for d in components] |
1042 | | - view.refresh(components) |
| 1045 | + try: |
| 1046 | + view._refresh(components) |
| 1047 | + except Exception: |
| 1048 | + _log.exception( |
| 1049 | + f"Failed to refresh View {view} from Message {message_id} due to mismatched state. Items may not have complete data." |
| 1050 | + ) |
0 commit comments