fix: 2 real-usage bugs found in end-to-end testing
Bug 1: search-github/search-twitter silently returned empty Root cause: result printing code was inside except block (never reached on success) Fix: moved result display code outside try/except Bug 2: Bilibili returned empty content when server IP is blocked Root cause: API returns code -404 but code treated it as success with empty data Fix: check API response code, show friendly message with proxy setup hint Also: GitHub search results now correctly show stars/forks/language from extra dict All found through real-usage E2E testing (not just install/config testing).
This commit is contained in:
@@ -47,7 +47,29 @@ class BilibiliChannel(Channel):
|
|||||||
timeout=15,
|
timeout=15,
|
||||||
)
|
)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
data = resp.json().get("data", {})
|
api_data = resp.json()
|
||||||
|
|
||||||
|
# Check for API errors (IP blocked, video not found, etc.)
|
||||||
|
if api_data.get("code") != 0:
|
||||||
|
msg = api_data.get("message", "Unknown error")
|
||||||
|
# Bilibili returns -404 when server IP is blocked
|
||||||
|
if api_data.get("code") in (-404, -403, -412):
|
||||||
|
return ReadResult(
|
||||||
|
title=f"Bilibili: {bv_id}",
|
||||||
|
content=f"⚠️ Bilibili blocked this request ({msg}). "
|
||||||
|
f"This usually means the server IP is blocked. "
|
||||||
|
f"Try: agent-eyes configure proxy http://user:pass@ip:port",
|
||||||
|
url=url,
|
||||||
|
platform="bilibili",
|
||||||
|
)
|
||||||
|
return ReadResult(
|
||||||
|
title=f"Bilibili: {bv_id}",
|
||||||
|
content=f"Bilibili API error: {msg} (code: {api_data.get('code')})",
|
||||||
|
url=url,
|
||||||
|
platform="bilibili",
|
||||||
|
)
|
||||||
|
|
||||||
|
data = api_data.get("data", {})
|
||||||
|
|
||||||
title = data.get("title", "")
|
title = data.get("title", "")
|
||||||
desc = data.get("desc", "")
|
desc = data.get("desc", "")
|
||||||
|
|||||||
+15
-21
@@ -570,28 +570,22 @@ async def _cmd_search(args):
|
|||||||
print(f"❌ Error: {e}", file=sys.stderr)
|
print(f"❌ Error: {e}", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not results:
|
if not results:
|
||||||
print("No results found.")
|
print("No results found.")
|
||||||
return
|
return
|
||||||
|
|
||||||
for i, r in enumerate(results, 1):
|
for i, r in enumerate(results, 1):
|
||||||
title = r.get("title") or r.get("name") or r.get("text", "")[:60]
|
title = r.get("title") or r.get("name") or r.get("text", "")[:60]
|
||||||
url = r.get("url", "")
|
url = r.get("url", "")
|
||||||
snippet = r.get("snippet") or r.get("description") or r.get("text", "")
|
snippet = r.get("snippet") or r.get("description") or r.get("text", "")
|
||||||
print(f"\n{i}. {title}")
|
print(f"\n{i}. {title}")
|
||||||
print(f" 🔗 {url}")
|
print(f" 🔗 {url}")
|
||||||
if snippet:
|
if snippet:
|
||||||
print(f" {snippet[:200]}")
|
print(f" {snippet[:200]}")
|
||||||
# Extra info for GitHub
|
# Extra info for GitHub
|
||||||
if "stars" in r:
|
extra = r.get("extra", {})
|
||||||
print(f" ⭐ {r['stars']} 🍴 {r.get('forks', 0)} 📝 {r.get('language', '')}")
|
if extra.get("stars"):
|
||||||
|
print(f" ⭐ {extra['stars']} 🍴 {extra.get('forks', 0)} 📝 {extra.get('language', '')}")
|
||||||
except ValueError as e:
|
|
||||||
print(f"⚠️ {e}", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
except Exception as e:
|
|
||||||
print(f"❌ Error: {e}", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user