Fix: Add infinite loop protection to debug script pagination
This commit is contained in:
@@ -102,6 +102,7 @@ def fetch_all_packages():
|
||||
current_token = ""
|
||||
page_count = 0
|
||||
MAX_PAGES = 15 # 🛑 Safety Limit for Debugging
|
||||
seen_tokens = set()
|
||||
|
||||
while True:
|
||||
try:
|
||||
@@ -128,7 +129,6 @@ def fetch_all_packages():
|
||||
break
|
||||
|
||||
data = response.json()
|
||||
# print(f" Raw Response: {json.dumps(data, ensure_ascii=False)[:200]}...") # Truncated
|
||||
|
||||
items = data.get("Result", {}).get("List", [])
|
||||
print(f" Found {len(items)} items in this page.")
|
||||
@@ -138,9 +138,6 @@ def fetch_all_packages():
|
||||
|
||||
next_token = data.get("Result", {}).get("NextToken", "")
|
||||
|
||||
# Debug Token Transition
|
||||
# print(f" Token: '{current_token}' -> '{next_token}'")
|
||||
|
||||
if not next_token:
|
||||
print(" ✅ No NextToken. Done.")
|
||||
break
|
||||
@@ -149,6 +146,13 @@ def fetch_all_packages():
|
||||
print(" ⚠️ NextToken did not change. Stopping.")
|
||||
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
|
||||
time.sleep(0.2)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user