diff --git a/src/asquare.py b/src/asquare.py index c3cae80..800e6da 100644 --- a/src/asquare.py +++ b/src/asquare.py @@ -124,8 +124,9 @@ async def get_item_by_variation_id(variation_id: str) -> dict: cursor = None page_count = 0 + max_pages = 50 # Safety limit to prevent infinite loops - while True: + while page_count < max_pages: page_count += 1 print(f"[@DEBUG] Searching page {page_count}...") @@ -151,6 +152,7 @@ async def get_item_by_variation_id(variation_id: str) -> dict: raise ValueError(f"No items found in LEGO category") else: # No more results + print(f"[@DEBUG] No more results on page {page_count}") break # Search through items on this page to find which has this variation @@ -188,8 +190,15 @@ async def get_item_by_variation_id(variation_id: str) -> dict: cursor = result_json.get("cursor") if not cursor: # No more pages + print(f"[@DEBUG] No more pages after page {page_count}") break + # If we get here, variation wasn't found + if page_count >= max_pages: + raise ValueError( + f"Variation {variation_id} not found after searching {max_pages} pages (possible infinite loop prevented)" + ) + raise ValueError( f"Variation {variation_id} not found in any LEGO category item (searched {page_count} pages)" )