From faa79c88c7f7b4e88ad6090f49dde55ccea785e9 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 6 Mar 2026 18:41:54 -0500 Subject: [PATCH] feat(scraper): add `on_error` callback to `scrape_contest_metadata` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: `scrape_contest_metadata` silently swallowed failures — the callback simply never fired, giving callers no way to detect or react to scraper errors. Solution: Add optional `on_error` parameter invoked on scraper failure or empty problems result. Backward-compatible — existing callers are unchanged. --- lua/cp/scraper.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/cp/scraper.lua b/lua/cp/scraper.lua index e488cc5..4004ba6 100644 --- a/lua/cp/scraper.lua +++ b/lua/cp/scraper.lua @@ -216,7 +216,7 @@ local function run_scraper(platform, subcommand, args, opts) end end -function M.scrape_contest_metadata(platform, contest_id, callback) +function M.scrape_contest_metadata(platform, contest_id, callback, on_error) run_scraper(platform, 'metadata', { contest_id }, { on_exit = function(result) if not result or not result.success then @@ -227,6 +227,9 @@ function M.scrape_contest_metadata(platform, contest_id, callback) ), { level = vim.log.levels.ERROR } ) + if type(on_error) == 'function' then + on_error() + end return end local data = result.data or {} @@ -238,6 +241,9 @@ function M.scrape_contest_metadata(platform, contest_id, callback) ), { level = vim.log.levels.ERROR } ) + if type(on_error) == 'function' then + on_error() + end return end if type(callback) == 'function' then