From 7b4c983be6994a3fded1a66f469c42105911bd67 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 21:47:39 +0000 Subject: [PATCH] Fix critical bugs: null checks and error handling Co-authored-by: fabrice404 <12575390+fabrice404@users.noreply.github.com> --- scraper/ics-generator.ts | 11 +++++++++-- scraper/index.ts | 16 +++++++++++----- scraper/scraper.ts | 4 +++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/scraper/ics-generator.ts b/scraper/ics-generator.ts index a8c2c7497..9c6bc8e51 100644 --- a/scraper/ics-generator.ts +++ b/scraper/ics-generator.ts @@ -49,7 +49,7 @@ export class ICSGenerator { for (const lang of this.calendar.languages) { const pathSportKey = sportKey || "all-sports"; let pathCalendar = "calendar"; - if (type != "all-events") { + if (type !== "all-events") { pathCalendar = type; } else if (nocKey) { pathCalendar = nocKey; @@ -150,7 +150,14 @@ export class ICSGenerator { flag: getFlag(team?.key || ""), }; } - const competitor = this.calendar.competitors.find(comp => comp.code === competitorId)!; + const competitor = this.calendar.competitors.find(comp => comp.code === competitorId); + if (!competitor) { + return { + noc: "", + name: competitorId, + flag: "🏳️", + }; + } return { noc: competitor.noc, name: competitor.name, diff --git a/scraper/index.ts b/scraper/index.ts index dda9a1d18..05991af70 100644 --- a/scraper/index.ts +++ b/scraper/index.ts @@ -4,10 +4,14 @@ import nodeCron from "node-cron"; import { Scraper } from "./scraper"; const main = () => { - nodeCron.schedule("*/10 * * * *", () => { - removeSync("./cache/schedules"); - const scraper = new Scraper(); - scraper.scrape(); + nodeCron.schedule("*/10 * * * *", async () => { + try { + removeSync("./cache/schedules"); + const scraper = new Scraper(); + await scraper.scrape(); + } catch (error) { + console.error("Error during scheduled scrape:", error); + } }); nodeCron.schedule("0 0 * * *", () => { @@ -16,7 +20,9 @@ const main = () => { }); const scraper = new Scraper(); - scraper.scrape(); + scraper.scrape().catch((error) => { + console.error("Error during initial scrape:", error); + }); }; main(); diff --git a/scraper/scraper.ts b/scraper/scraper.ts index dcbd510e2..db53b6922 100644 --- a/scraper/scraper.ts +++ b/scraper/scraper.ts @@ -147,7 +147,9 @@ export class Scraper { for (const noc of this.nocs) { const found = data.nocs.find((n) => n.id === noc.key); - this.setNoc(found.id, found.name, lang.code); + if (found) { + this.setNoc(found.id, found.name, lang.code); + } } } }