fix: refuse an emudeck scrape with no cores

This commit is contained in:
Abdessamad Derraz committed 2026-10-06 12:23:48 +02:00
1 parent e723f346f9
commit 91e113a7d3
2 files changed
+21 -8

No files matched your search

+10 -8
View File
@@ -22,6 +22,7 @@ try:
BaseScraper, BaseScraper,
BiosRequirement, BiosRequirement,
fetch_github_latest_version, fetch_github_latest_version,
github_headers,
requirement_entry, requirement_entry,
) )
except ImportError: except ImportError:
@@ -29,6 +30,7 @@ except ImportError:
BaseScraper, BaseScraper,
BiosRequirement, BiosRequirement,
fetch_github_latest_version, fetch_github_latest_version,
github_headers,
requirement_entry, requirement_entry,
) )
@@ -462,17 +464,15 @@ class Scraper(BaseScraper):
skip = {"retroarch_maincfg", "retroarch"} skip = {"retroarch_maincfg", "retroarch"}
try: try:
req = urllib.request.Request( req = urllib.request.Request(api_url, headers=github_headers())
api_url, with urllib.request.urlopen(req, timeout=30) as resp:
headers={"User-Agent": "retrobios-scraper/1.0"}, data = json.loads(resp.read())
) except (urllib.error.URLError, json.JSONDecodeError) as e:
data = json.loads(urllib.request.urlopen(req, timeout=30).read()) raise RuntimeError(f"cannot list EmuDeck EmuScripts: {e}") from e
except (urllib.error.URLError, OSError):
return []
cores: list[str] = [] cores: list[str] = []
seen: set[str] = set() seen: set[str] = set()
for entry in data: for entry in data if isinstance(data, list) else []:
name = entry.get("name", "") name = entry.get("name", "")
if not name.endswith(".sh"): if not name.endswith(".sh"):
continue continue
@@ -487,6 +487,8 @@ class Scraper(BaseScraper):
if core not in seen: if core not in seen:
seen.add(core) seen.add(core)
cores.append(core) cores.append(core)
if not cores:
raise RuntimeError(f"no emulator script in {api_url}")
return sorted(cores) return sorted(cores)
+11
View File
@@ -278,3 +278,14 @@ class UnreadableReleaseStopsTheScrape(unittest.TestCase):
with mock.patch.dict("os.environ", {"GITHUB_TOKEN": "t0k"}): with mock.patch.dict("os.environ", {"GITHUB_TOKEN": "t0k"}):
self.assertEqual(github_headers()["Authorization"], "Bearer t0k") self.assertEqual(github_headers()["Authorization"], "Bearer t0k")
def test_emudeck_cores_raise(self):
"""EmuDeck wrote cores: [] when the GitHub listing was refused."""
from unittest import mock
from scraper.emudeck_scraper import Scraper
with mock.patch("urllib.request.urlopen", self._refuse), self.assertRaises(
RuntimeError
):
Scraper()._fetch_installed_emulators()