Fix: Add infinite loop protection to debug script pagination

This commit is contained in:
kim
2026-01-29 17:34:39 +08:00
parent ac62783fc6
commit aeb89b69a0
+8 -4
View File
@@ -102,6 +102,7 @@ def fetch_all_packages():
current_token = "" current_token = ""
page_count = 0 page_count = 0
MAX_PAGES = 15 # 🛑 Safety Limit for Debugging MAX_PAGES = 15 # 🛑 Safety Limit for Debugging
seen_tokens = set()
while True: while True:
try: try:
@@ -128,7 +129,6 @@ def fetch_all_packages():
break break
data = response.json() data = response.json()
# print(f" Raw Response: {json.dumps(data, ensure_ascii=False)[:200]}...") # Truncated
items = data.get("Result", {}).get("List", []) items = data.get("Result", {}).get("List", [])
print(f" Found {len(items)} items in this page.") print(f" Found {len(items)} items in this page.")
@@ -138,9 +138,6 @@ def fetch_all_packages():
next_token = data.get("Result", {}).get("NextToken", "") next_token = data.get("Result", {}).get("NextToken", "")
# Debug Token Transition
# print(f" Token: '{current_token}' -> '{next_token}'")
if not next_token: if not next_token:
print(" ✅ No NextToken. Done.") print(" ✅ No NextToken. Done.")
break break
@@ -149,6 +146,13 @@ def fetch_all_packages():
print(" ⚠️ NextToken did not change. Stopping.") print(" ⚠️ NextToken did not change. Stopping.")
break break
if next_token in seen_tokens:
print(
f" ⚠️ Detected pagination cycle with token {next_token[:10]}... Stopping."
)
break
seen_tokens.add(next_token)
current_token = next_token current_token = next_token
time.sleep(0.2) time.sleep(0.2)
except Exception as e: except Exception as e: