From 2e61854be5cc49b6a1c80a8aa61f0f856637df7b Mon Sep 17 00:00:00 2001 From: Matthew Jackson Date: Fri, 6 Mar 2026 22:14:28 -0800 Subject: [PATCH] Wrap keyword search in try/catch for resilience Failed keywords log the error and continue to the next one. Not marked complete, so they'll be retried on next run. Also await async onPage callback. Co-Authored-By: Claude Opus 4.6 --- lib/linkedin.mjs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/linkedin.mjs b/lib/linkedin.mjs index 95ce666..a135ea9 100644 --- a/lib/linkedin.mjs +++ b/lib/linkedin.mjs @@ -40,6 +40,7 @@ export async function searchLinkedIn(page, search, { onPage, onKeyword } = {}) { } await page.waitForTimeout(PAGE_LOAD_WAIT); + try { let pageNum = 0; while (pageNum < LINKEDIN_MAX_SEARCH_PAGES) { // Scroll to load all cards @@ -129,7 +130,7 @@ export async function searchLinkedIn(page, search, { onPage, onKeyword } = {}) { jobs.push(job); } - if (pageJobs.length > 0 && callbacks.onPage) callbacks.onPage(pageJobs); + if (pageJobs.length > 0 && callbacks.onPage) await callbacks.onPage(pageJobs); const nextBtn = await page.$('button[aria-label="View next page"]'); if (!nextBtn) break; @@ -137,6 +138,11 @@ export async function searchLinkedIn(page, search, { onPage, onKeyword } = {}) { await page.waitForTimeout(PAGE_LOAD_WAIT); pageNum++; } + } catch (kwErr) { + console.error(` ❌ Keyword "${keyword}" failed: ${kwErr.message}`); + // Don't mark as complete — will be retried on next run + continue; + } // Mark keyword complete after all its pages are done callbacks.onKeyword?.(ki); }