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:
parent
c851bd64b9
commit
afe3aceb61
2 changed files with 38 additions and 22 deletions
|
|
@ -47,7 +47,29 @@ class BilibiliChannel(Channel):
|
|||
timeout=15,
|
||||
)
|
||||
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", "")
|
||||
desc = data.get("desc", "")
|
||||
|
|
|
|||
|
|
@ -570,28 +570,22 @@ async def _cmd_search(args):
|
|||
print(f"❌ Error: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if not results:
|
||||
print("No results found.")
|
||||
return
|
||||
if not results:
|
||||
print("No results found.")
|
||||
return
|
||||
|
||||
for i, r in enumerate(results, 1):
|
||||
title = r.get("title") or r.get("name") or r.get("text", "")[:60]
|
||||
url = r.get("url", "")
|
||||
snippet = r.get("snippet") or r.get("description") or r.get("text", "")
|
||||
print(f"\n{i}. {title}")
|
||||
print(f" 🔗 {url}")
|
||||
if snippet:
|
||||
print(f" {snippet[:200]}")
|
||||
# Extra info for GitHub
|
||||
if "stars" in r:
|
||||
print(f" ⭐ {r['stars']} 🍴 {r.get('forks', 0)} 📝 {r.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)
|
||||
for i, r in enumerate(results, 1):
|
||||
title = r.get("title") or r.get("name") or r.get("text", "")[:60]
|
||||
url = r.get("url", "")
|
||||
snippet = r.get("snippet") or r.get("description") or r.get("text", "")
|
||||
print(f"\n{i}. {title}")
|
||||
print(f" 🔗 {url}")
|
||||
if snippet:
|
||||
print(f" {snippet[:200]}")
|
||||
# Extra info for GitHub
|
||||
extra = r.get("extra", {})
|
||||
if extra.get("stars"):
|
||||
print(f" ⭐ {extra['stars']} 🍴 {extra.get('forks', 0)} 📝 {extra.get('language', '')}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue